<?php
namespace app\mobile\controller;

use app\model\Record; 
use app\model\Theme; 
use app\model\Worker; 
use app\model\Fans; 
use app\model\Userdata; 

class Daping extends Base
{
    public function Daping()
    {global $_G, $_P;//每页分页数量// $fans = $this->checkuser();//判断IE浏览器if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE ||    strpos($_SERVER['HTTP_USER_AGENT'], 'Trident') !== FALSE) {    return_msg('不支持IE浏览器打开，请切到谷歌浏览器打开');}$themeid = intval($_P['themeid']);if($themeid < 0){    return_msg('管理后台地址不正确');}$system=$_G['system'];$theme = Theme::getThemeById($themeid);$config = 	Theme::getConfig($themeid);if(empty($theme['id'])){    return_msg('管理后台地址不正确');}$get_dpkey = $_P['dpkey'];$dpkey=Theme::getDapingKey($theme);if ($dpkey != trim($get_dpkey)){    return_msg('管理后台地址不正确!');}$msg = Worker::gethoutaistats();if (!empty($msg)) {    return_msg($msg);}$link_type = $_P['linkType'];$limit_page =10;if($link_type=='h5'){    $limit_page =20;}define('PAGE_LIMIT',$limit_page);define('DAPING_THEMEID',$themeid);$company = intval($_P['company']);// if ($system['is_multiple_merchants']){// 	$shop=db_find("SELECT * FROM ".tablename(t_shangjia)." WHERE id= '{$company}'");// 	$shopname=$shop['name'];// }//$all_where = " themeid=$themeid";if ($config['showalldata']==0) {    $all_where = "themeid=$themeid";    $theme_r = "r.themeid=$themeid";}else{    $all_where = "themeid>0";    $theme_r = "r.themeid>0";}//设置公共缓存$alldata_cachekey = 'daping_new'.$_G['mpid'].MODULE_NAME.$themeid.'alldata';//数据缓存$data_cachekey = 'daping_new'.$_G['mpid'].MODULE_NAME.$themeid.'data';$start_time = $_P['start_time'];    //开始时间$end_time = $_P['end_time'];       //开始时间$time_select  = 0;$workerreport_time_where = '';$addtime_where = '';$createtime_where = '';$start_strtotime = '';$end_strtotime = '';$need_new  = 1;$yukuan_hour = '';if ($config['yukuan'] > 0 && TIMESTAMP > $config['yukuantime'] && $config['presaledaping']==1) {    $yukuan_hour = date('Y-m-d H', $config['yukuantime']).':00:00';}if($start_time&&$end_time){    $workerreport_time_where = " and hour>='{$start_time}' and hour<'{$end_time}'";    //转为时间戳    $start_strtotime = strtotime($start_time);    $end_strtotime = strtotime($end_time);    $addtime_where = " and addtime between $start_strtotime and $end_strtotime";    $createtime_where = " and create_time >='{$start_time}' and create_time<'{$end_time}'";    $addtime_where_r = " and r.addtime between $start_strtotime and $end_strtotime";    $need_new  = 0;    cache_delete($data_cachekey);      //删除数据缓存}elseif($yukuan_hour){    $start_time = $yukuan_hour;    $workerreport_time_where = " and hour>='{$start_time}'";    //转为时间戳    $start_strtotime = strtotime($start_time);    $addtime_where = " and addtime >= $start_strtotime";    $createtime_where = " and create_time>='{$start_time}'";    $addtime_where_r = " and r.addtime>='".$start_strtotime ."'";}//24小时实时数据$end_hour = $end_time?$end_time:date('Y-m-d H',strtotime("+1 hour")).':00:00';$start = strtotime('-1 day +1 hour',strtotime($end_hour));; //获得往前推24小时的时间点。$date = [];for ($i=$start; $i<=strtotime($end_hour); $i+=3600)  //3600秒是按每小时生成一条，如果按天或者月份换算成秒即可{    $hour = date('Y-m-d H',$i).':00:00';    $date[] = $hour; //存储过去24内每个小时的节点}if(!$_G['isajax']) {   //首次进入    cache_delete($data_cachekey);    if($system['is_multiple_merchants'] && $config['showshop']==0){        $shangjia_list = db_select("SELECT id,name FROM ".tablename (t_shangjia),array(),'id');    }else{        $shangjia_list = array();    }    //查询团队    $team_list =  db_select("SELECT id,company,name FROM ".tablename (t_team),array(),'id');    //查询员工    $worker_list =  db_select("SELECT id,themeid,uid,username,company,team,superior,level,concat(themeid,'_',uid) as theme_uid FROM ".tablename ( t_worker)." WHERE {$all_where}" ,array(),'theme_uid');    $workerids_array = array_column($worker_list, "uid");    $workerids  = '';    if($workerids_array){        $workerids = implode(',',$workerids_array);    }    $themeid = intval($_P['themeid']);    //数据放入缓存    cache_write($alldata_cachekey,[        'shangjia_list' => $shangjia_list,        'team_list' => $team_list,        'worker_list' => $worker_list,        'workerids'=> $workerids,    ]);    setcookie("end_hour");    $url = '/'.createMobileUrl('daping',array('themeid'=>$themeid,'dpkey'=>$get_dpkey));    if(stripos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') === false || empty($_G['openid'])){        $return_clicent = get_defined_vars();
return view('/fcworker/daping_web', $return_clicent);    }else{        $return_clicent = get_defined_vars();
return view('/fcworker/daping_mobile', $return_clicent);    }}else {      //ajax 请求    $op = $_P['op'];    $alldata_settings = cache_load($alldata_cachekey);    $shangjia_list = $alldata_settings['shangjia_list'];    $team_list = $alldata_settings['team_list'];    $worker_list = $alldata_settings['worker_list'];    $workerids = $alldata_settings['workerids'];    //创建数据缓存    $settings = cache_load($data_cachekey);    if($system['ruanjian']==5){    //砍价        if($config['bargain_minprice']==0&&$config['bargain_joinprice']==0){            $ispay=" 1=1 ";            $ispay_r = " 1=1 ";        }else{            $ispay="status > 0";            $ispay_r = 'r.'.$ispay;        }    }else{        if (Record::isFreeJoin($config,$themeid)){            $ispay="1=1";            $ispay_r = " 1=1 ";        }else{            $ispay="status > 0";            $ispay_r = 'r.'.$ispay;        }    }    if ($config['daping_xuni']!=1){        $xuni_show = " || status =-2";        $xuni_show_r = " || r.status =-2";    }    $is_multiple_merchants = 0;    if(($system['is_multiple_merchants'] && $config['showshop']==0)){           $is_multiple_merchants = 1;    }    //查询员工汇总表最新小时的数据    if ($need_new == 1) {        /*$now_hour = date('Y-m-d H') . ':00:00';        $now_hour_sql = "SELECT hour,                                    ifnull(sum(newfans),0) as all_fans,                                    ifnull(sum(record),0) as all_record,                                    ifnull(sum(recordzx),0) as all_recordzx,                                    ifnull(sum(recordxx),0) as all_recordzz,                                    ifnull(sum(fee),0) as all_fee,                                    ifnull(sum(scansum),0) as all_scansum,                                    ifnull(sum(forward),0) as all_forward                                 FROM " . tablename(t_workerreport) . " WHERE {$all_where}  AND hour ='{$now_hour}'";        $new_hour_data = db_find($now_hour_sql);        if (isset($settings['new_data'])) {            $cache_new_data = $settings['new_data'];            $diff_result = array_diff_assoc($cache_new_data, $new_hour_data);            if ($diff_result) {   //有差值  数据有变动                $return_cache = 0;            } else {        //没有差值 数据没有变动  返回缓存数据                $return_cache = 1;            }        } else {            $return_cache = 0;            $cache_array['new_data'] = $new_hour_data;        }*/        //总数据        $all_sql = "SELECT COUNT(case when  {$ispay} {$xuni_show} then 1 end) as all_record,COUNT(case when status = -1 then 1 end) as refund FROM " .                    tablename ( t_record ) . "  WHERE {$all_where} {$addtime_where}";        $order = db_find($all_sql);        $order_count = $order['all_record']-$order['refund'];        if(empty($settings)||$settings['all_data']['all_record']<>$order_count||time()-$settings['lasttime']>60) {   //没有缓存或者缓存数据不匹配            $return_cache = 0;        }else{            $return_cache = 1;        }    } else {        $return_cache = 0;    }    $ratio_type = $_P['ratio_type'];    if ($return_cache == 1 && $settings['ratio_data'] && $ratio_type == $settings['ratio_type']) {        $ratio_data = $settings['ratio_data'];    } else {        $ratio_data = self::ratioData($system, $config, $themeid, $all_where, $addtime_where, $ratio_type);        if ($need_new == 1) {            $cache_array['ratio_type'] = $ratio_type;            $cache_array['ratio_data'] = $ratio_data;        }    }    $result['ratio_data'] = $ratio_type;    $rank_type = $_P['rank_type'];    if ($return_cache == 1 && $settings['rank_list'] && $rank_type == $settings['rank_type']) {        $rank_list = $settings['rank_list'];    } else {        $rank_list = self::rankData($all_where, $addtime_where, $workerids, $rank_type);        if ($need_new == 1) {            $cache_array['rank_type'] = $rank_type;            $cache_array['rank_list'] = $rank_list;        }    }    $cache_order_type = 'order_list';//    if($link_type=='h5'){//        $cache_order_type = 'order_list_h5';//    }    if ($return_cache == 1 && $settings[$cache_order_type]) {        $order_list = $settings[$cache_order_type];    } else {        $order_where = $all_where.' and ('.$ispay. $xuni_show.')' .$addtime_where;        $order_list = self::orderList($shangjia_list,$team_list,$worker_list,$order_where,$is_multiple_merchants);        if ($need_new == 1) {            $cache_array[$cache_order_type] = $order_list;        }    }    $result['rank_list'] = $rank_list;    $page = $_P['page'];    $orderField = $_P['orderField'];    $orderType = $_P['orderType'];    switch ($op) {        case  'base':   //返回通用数据            $base_data = self::baseData($themeid,$system,$data_cachekey);            return_json(0,'',$base_data);            break;        case 'ratio':      //比例切换返回            return_json(0, '', $ratio_data);            break;        case  'rank':      //排名切换            return_json(0, '', $rank_list);            break;        case 'hour_info':            $hour_type = $_P['hour_type'];            $target_id = $_P['target_id'];            $field_type = $_P['field_type'];            $hour_status = $_P['hour_status'];            if($_COOKIE['end_hour']){                $end_hour = $_COOKIE['end_hour'];            }            if($hour_status=='before'){                $end_hour  = date('Y-m-d H',strtotime('-8 hours',strtotime($end_hour))).":00:00";                setcookie('end_hour',$end_hour);            }elseif($hour_status=='after'){                $end_hour  = date('Y-m-d H',strtotime('+8 hours',strtotime($end_hour))).":00:00";                setcookie('end_hour',$end_hour);            }            $hour_info = self::hourInfo($theme,$is_multiple_merchants,$alldata_settings,$all_where,$end_hour,$hour_type,$target_id,$field_type);            return_json(0, '', $hour_info);            break;        case 'worker_rank_list':    //员工排名列表            $team = isset($_P['team']) ?$_P['team']:-1;            $worker_rank_list = self::workerRankList($shangjia_list,$team_list, $worker_list, $all_where, $is_multiple_merchants,$workerreport_time_where, $page, $orderField, $orderType,$team);            $worker_rank_list['order_list'] = $order_list;            return_json(0, '', $worker_rank_list);            break;        case 'team_rank_list':     //团队排名列表            $company = isset($_P['company']) ?$_P['company']:-1;            $team_rank_list = self::teamRankList($team_list, $all_where, $start_time, $end_time, $page, $orderField, $orderType,$company);            $team_rank_list['order_list'] = $order_list;            return_json(0, '', $team_rank_list);            break;        case 'shangjia_rank_list':            $shangjia_rank_list = self::shangjiaRankList($shangjia_list, $all_where, $start_time, $end_time, $page, $orderField,$orderType);            $shangjia_rank_list['order_list'] = $order_list;            return_json(0, '', $shangjia_rank_list);            break;        case 'browse_list':        //浏览列表            $browse_page_list = self::browseList($alldata_settings,$theme_r,$start_time,$end_time, $page, $orderField,$orderType);            $browse_page_list['order_list'] = $order_list;            return_json(0, '', $browse_page_list);            break;        case 'fans_cj_list':       //粉丝成交            $fans_cj_list = self::fansCjRankList($all_where, $addtime_where, $alldata_settings, $page, $orderField, $orderType);            $fans_cj_list['order_list'] = $order_list;            return_json(0, '', $fans_cj_list);            break;        case 'fans_tj_list':      //粉丝推荐            $fans_tj_list = self::fansTjRankList($all_where, $addtime_where, $alldata_settings, $page, $orderField, $orderType);            $fans_tj_list['order_list'] = $order_list;            return_json(0, '', $fans_tj_list);            break;        case 'fans_zl_list':      //粉丝助力            $fans_zl_list = self::fansZlRankList($all_where, $start_strtotime,$end_strtotime, $alldata_settings, $page, $orderField, $orderType);            $fans_zl_list['order_list'] = $order_list;            return_json(0, '', $fans_zl_list);            break;        case 'tuan_list':          //团长排名            $tuan_list = self::tuanRankList($alldata_settings,$all_where, $addtime_where, $page, $orderField, $orderType);            $tuan_list['order_list'] = $order_list;            return_json(0, '', $tuan_list);            break;        case 'comm_list':         //红包排名            $comm_list = self::commRankList($alldata_settings,$all_where, $addtime_where, $page, $orderField, $orderType);            $comm_list['order_list'] = $order_list;            return_json(0, '', $comm_list);            break;        //修改是否弹窗        case 'change_alert': //             $change_alert_status = $_P['change_alert_status'];             setcookie('alert_status',$change_alert_status);             return_json(0, '');            break;    }    $xuni_data = array();    if ($config['daping_xuni'] != 1) {        $xuni_sql = " SELECT  themeid,workerid,                               concat(themeid,'_',workerid) as themeid_worker,                                   COUNT(id) as xuni_num,SUM(fee) as xuni_fee FROM " . tablename(t_record) . "                        WHERE {$all_where} {$addtime_where} and status =-2 GROUP BY workerid";        $xuni_data = db_select($xuni_sql, array(), 'themeid_worker');    }    if ($return_cache == 1 && isset($settings['hour_array'])) {        $hour_array = $settings['hour_array'];    } else {        $hour_where = " and hour>'{$date[0]}' and hour<='{$end_hour}'";   //24小时前开始时间        $hour_sql = "SELECT hour,                           sum(newfans) as all_fans,                           sum(record) as all_record,                           sum(recordzx) as all_recordzx,                           sum(recordxx) as all_recordxx,                           sum(fee) as all_fee,                           sum(scansum) as all_scansum,                           sum(forward) as all_forward                         FROM " . tablename(t_workerreport) . " WHERE {$all_where} {$hour_where} GROUP BY hour";        $hour_array = [];        $hour_list = db_select($hour_sql, array(), 'hour');        $end_hour_data = end($hour_list);        $xuni_record = array();        if($config['daping_xuni'] != 1){            $xuni_sql = "SELECT count(id) as xuni_num,from_unixtime(addtime,'%Y-%m-%d %H:00:00') as hour                          FROM ". tablename(t_record) . " WHERE themeid = {$themeid}                          and from_unixtime(addtime,'%Y-%m-%d %H:00:00')>'{$date[0]}'                          and from_unixtime(addtime,'%Y-%m-%d %H:00:00')<='{$end_hour}' and status =-2 group by hour order by hour asc";            $xuni_record =  db_select($xuni_sql,array(),'hour');        }        //凌晨数组        $hours_data = array();        foreach ($date as $k => $d) {            $hour = date('G', strtotime($d));            $xuni_info = 0;            if(isset($xuni_record[$d])){                $xuni_info = $xuni_record[$d]['xuni_num'];            }            if($hour<=7){                $hour_str = '7:00';                $wee_hours_key = substr($d,0,10).' 07:00:00';                if(isset($hours_data[$wee_hours_key])){                    $old_data =  $hours_data[$wee_hours_key];                    $old_data['fans'] +=  isset($hour_list[$d]['all_fans']) ? intval($hour_list[$d]['all_fans']):0;                    $old_data['record'] += isset($hour_list[$d]['all_record']) ? intval($hour_list[$d]['all_record']+$xuni_info):$xuni_info;                    $old_data['recordzx'] += isset($hour_list[$d]['all_recordzx']) ? intval($hour_list[$d]['all_recordzx']):0;                    $old_data['recordxx'] += isset( $hour_list[$d]['all_recordxx']) ? intval($hour_list[$d]['all_recordxx']):0;                    $old_data['fee'] += isset($hour_list[$d]['all_fee']) ? intval($hour_list[$d]['all_fee']):0;                    $old_data['scansum'] += isset($hour_list[$d]['all_scansum']) ? intval($hour_list[$d]['all_scansum']):0;                    $old_data['forward'] += isset($hour_list[$d]['all_forward']) ? intval($hour_list[$d]['all_forward']):0;                }else{                    $hours_data[$wee_hours_key]['hour'] = $hour_str;                    $hours_data[$wee_hours_key]['fans'] =  isset($hour_list[$d]['all_fans']) ? intval($hour_list[$d]['all_fans']):0;                    $hours_data[$wee_hours_key]['record'] = isset($hour_list[$d]['all_record']) ? intval($hour_list[$d]['all_record']+$xuni_info):$xuni_info;                    $hours_data[$wee_hours_key]['recordzx'] = isset($hour_list[$d]['all_recordzx']) ? intval($hour_list[$d]['all_recordzx']):0;                    $hours_data[$wee_hours_key]['recordxx'] =isset( $hour_list[$d]['all_recordxx']) ? intval($hour_list[$d]['all_recordxx']):0;                    $hours_data[$wee_hours_key]['fee'] = isset($hour_list[$d]['all_fee']) ? intval($hour_list[$d]['all_fee']):0;                    $hours_data[$wee_hours_key]['scansum'] = isset($hour_list[$d]['all_scansum']) ? intval($hour_list[$d]['all_scansum']):0;                    $hours_data[$wee_hours_key]['forward'] = isset($hour_list[$d]['all_forward']) ? intval($hour_list[$d]['all_forward']):0;                }            }else{                $hours_data[$d]['hour'] = $hour.':00';                $hours_data[$d]['fans'] =  isset($hour_list[$d]['all_fans']) ? intval($hour_list[$d]['all_fans']):0;                $hours_data[$d]['record'] = isset($hour_list[$d]['all_record']) ? intval($hour_list[$d]['all_record']+$xuni_info):$xuni_info;                $hours_data[$d]['recordzx'] = isset($hour_list[$d]['all_recordzx']) ? intval($hour_list[$d]['all_recordzx']):0;                $hours_data[$d]['recordxx'] =isset( $hour_list[$d]['all_recordxx']) ? intval($hour_list[$d]['all_recordxx']):0;                $hours_data[$d]['fee'] = isset($hour_list[$d]['all_fee']) ? intval($hour_list[$d]['all_fee']):0;                $hours_data[$d]['scansum'] = isset($hour_list[$d]['all_scansum']) ? intval($hour_list[$d]['all_scansum']):0;                $hours_data[$d]['forward'] = isset($hour_list[$d]['all_forward']) ? intval($hour_list[$d]['all_forward']):0;            }        }//        $hour_array = array();        foreach($hours_data as $d){            $hour_array['hour'][] = $d['hour'];            $hour_array['fans'][] = $d['fans'];            $hour_array['record'][] = $d['record'];            $hour_array['recordzx'][] = $d['recordzx'];            $hour_array['recordxx'][] = $d['recordxx'];            $hour_array['fee'][] = $d['fee'];            $hour_array['scansum'][] = $d['scansum'];            $hour_array['forward'][] = $d['forward'];        }        if ($need_new == 1) {            $cache_array['hour_array'] = $hour_array;        }    }//    $hour_array['hour'][] = $hour.':00';//    $hour_key = $d;//    if (isset($hour_list[$d])||$xuni_info>0) {//        $hour_array['fans'][] = $hour_list[$d] ? intval($hour_list[$d]['all_fans']):0;//        $hour_array['record'][] = $hour_list[$d] ? intval($hour_list[$d]['all_record']+$xuni_info):$xuni_info;//        $hour_array['recordzx'][] = $hour_list[$d] ? intval($hour_list[$d]['all_recordzx']):0;//        $hour_array['recordxx'][] = $hour_list[$d] ? intval($hour_list[$d]['all_recordxx']):0;//        $hour_array['fee'][] = $hour_list[$d] ? intval($hour_list[$d]['all_fee']):0;//        $hour_array['scansum'][] = $hour_list[$d] ? intval($hour_list[$d]['all_scansum']):0;//        $hour_array['forward'][] = $hour_list[$d] ? intval($hour_list[$d]['all_forward']):0;//    } else {//        $hour_array['fans'][] = 0;//        $hour_array['record'][] = 0;//        $hour_array['recordzx'][] = 0;//        $hour_array['recordxx'][] = 0;//        $hour_array['fee'][] = 0;//        $hour_array['scansum'][] = 0;//        $hour_array['forward'][] = 0;//    }    if ($return_cache == 1) {        $all_data = $settings['all_data'];        $worker_rank = $settings['worker_rank'];        $team_rank = $settings['team_rank'];        $team_rank_array = $settings['team_list'];        $worker_rank_chart = $settings['worker_rank_chart'];    } else {        $workerreport_sql = "SELECT  themeid,workerid,                                    concat(themeid,'_',workerid) as themeid_worker,                                         sum(newfans) as all_fans,                                    sum(record)-sum(refund) + sum(recordxx) as all_record,                                    sum(fee) as all_fee,                                    sum(scansum) as all_scansum,                                    sum(forward) as all_forward,                                    sum(refundfee) as all_refundfee,                                    sum(refund) as all_refund                                FROM " . tablename(t_workerreport) . " WHERE {$all_where} {$workerreport_time_where}                                 GROUP BY themeid,workerid ORDER BY  all_record DESC,all_scansum DESC,all_forward DESC";        $workerreport = db_select($workerreport_sql, array(),'themeid_worker');        $all_record = array_sum(array_column($workerreport, 'all_record'));        if($xuni_data){            $xuni_workerids = array_keys($xuni_data);            $report_workerids = array_keys($workerreport);            $diff_workerid =  array_diff($xuni_workerids,$report_workerids);            if($diff_workerid){                foreach ($diff_workerid as $w){                    $tm_wk = explode('_',$w);                    $workerid = $tm_wk[1];                    $workerreport[$w]  =  [                                  'workerid'  => $workerid,                                  'all_fans'  => 0,                                  'all_record'  => 0,                                  'all_fee'  => 0,                                  'all_scansum'  => 0,                                  'all_forward'  => 0,                                  'all_refundfee'  => 0,                                  'all_refund'  => 0                        ];                }            }            $all_xuni = array_sum(array_column($xuni_data, 'xuni_num'));        }else{            $all_xuni = 0;        }        $all_record = $all_record + $all_xuni;        if($all_record<$order_count){     //补充未归属            //未归属            $weiguishu_sql = " SELECT  workerid,COUNT(id) as weiguishu_num,SUM(fee) as weiguishu_fee FROM " . tablename(t_record) . "                                WHERE {$all_where} and {$ispay} {$addtime_where} and workerid = 0 ";            $weiguishu_data = db_find($weiguishu_sql);            if($weiguishu_data &&  $weiguishu_data['weiguishu_num']+$all_record=$order_count){                  if(isset($workerreport[0])){                      $workerreport[0]['all_record'] =  $workerreport[0]['all_record'] + $weiguishu_data['weiguishu_num'];                      $workerreport[0]['all_fee'] =  $workerreport[0]['all_fee'] + $weiguishu_data['weiguishu_fee'];                  }else{                      $workerreport[0]  =  [                          'workerid'  => 0,                          'all_fans'  => 0,                          'all_record'  =>$weiguishu_data['weiguishu_num'],                          'all_fee'  => $weiguishu_data['weiguishu_fee'],                          'all_scansum'  => 0,                          'all_forward'  => 0,                          'all_refundfee'  => 0,                          'all_refund'  => 0                      ];                  }            }        }        //商家数据        $shop_data = array();        //总数据        $all_data = array(            'all_fans' => 0,            'all_record' => $all_record,            'all_recordzx' => 0,            'all_recordxx' => 0,            'all_fee' => 0,            'all_scansum' => 0,            'all_forward' => 0,            'all_refund' => 0,        );        $test_record = 0;        //员工数据        $worker_data = array();        foreach ($workerreport as  $k => $w) {            $xuni_num = 0;            $xuni_fee = 0;            if ($xuni_data && $xuni_data[$k]) {                $worker_xuni = $xuni_data[$k];                $xuni_num = $worker_xuni['xuni_num'];                $xuni_fee = $worker_xuni['xuni_fee'];            }            $worker_info = $worker_list[$k];            if ($worker_info) {      //存在员工                if($is_multiple_merchants){  //异业联盟                    $company_info = $shangjia_list[$worker_info['company']];                    $company_name = '';                    if($company_info){                        $company_name = trim($company_info['name']);                        $team_name = mb_substr($company_name,0,4);                    }else{                        $team_name = '无队名';                    }                }else{                    $team_info = $team_list[$worker_info['team']];                    $team_name = $team_info ? mb_substr($team_info['name'],0,4) : '无队名';                }                $w['company'] =  $worker_info['company'];                $w['team'] = $worker_info['team'];                $w['teamname'] = $team_name;                $w['username'] = self::getNickname($worker_info['username'],3,2) ;                $w['all_record'] = $w['all_record'] + $xuni_num;                $w['all_fee'] = $w['all_fee'] + $xuni_fee;                $worker_data[$k] = $w;            } else {                 //员工不存在或者已删除                $theme_key = $w['themeid'].'_0';                if (!isset($worker_data[$theme_key])) {                    $w['teamname'] = '无名队';                    $w['username'] = '未归属';                    $w['workerid'] = 0;                    $w['team'] = 0;                    $w['company'] = 0;                    $w['all_record'] = $w['all_record'] + $xuni_num;                    $w['all_fee'] = $w['all_fee'] + $xuni_fee;                    $worker_data[$theme_key] = $w;                } else {                    $worker_data[$theme_key]['all_fans'] = $worker_data[$theme_key]['all_fans'] + $w['all_fans'];                    $worker_data[$theme_key]['all_record'] = $worker_data[$theme_key]['all_record'] + $w['all_record'] + $xuni_num;                    // $worker_data[0]['all_recordzx'] = $worker_data[0]['all_recordzx']+$w['all_recordzx'];                    // $worker_data[0]['all_recordxx'] =  $worker_data[0]['all_recordxx']+$w['all_recordxx'];                    $worker_data[$theme_key]['all_fee'] = $worker_data[$theme_key]['all_fee'] + $w['all_fee'] + $xuni_fee;                    $worker_data[$theme_key]['all_scansum'] = $worker_data[$theme_key]['all_scansum'] + $w['all_scansum'];                    $worker_data[$theme_key]['all_forward'] = $worker_data[$theme_key]['all_forward'] + $w['all_forward'];                    $worker_data[$theme_key]['all_refundfee'] = $worker_data[$theme_key]['all_refundfee'] + $w['all_refundfee'];                    $worker_data[$theme_key]['all_refund'] = $worker_data[$theme_key]['all_refund'] + $w['all_refund'];                }            }            $all_data['all_fans'] += $w['all_fans'];          //  $all_data['all_record'] += $w['all_record'];            //$all_data['all_recordzx'] += $w['all_recordzx'];            //$all_data['all_recordxx'] += $w['all_recordxx'];            $all_data['all_fee'] += $w['all_fee'];            $all_data['all_scansum'] += $w['all_scansum'];            $all_data['all_forward'] += $w['all_forward'];            $all_data['all_refundfee'] += $w['all_refundfee'];            $all_data['all_refund'] += $w['all_refund'];            $test_record += $w['all_record'];        }        $worker_rank_limit = 20;        if($link_type=='h5'){            $worker_rank_limit = 10;        }        if (count($worker_data) > 10) {            $worker_rank = array_slice(array_values($worker_data), 0, $worker_rank_limit);        } else {            $worker_rank = array_values($worker_data);        }        $worker_record_sort = array_column($worker_rank, 'all_record');        $worker_forward_sort = array_column($worker_rank, 'all_forward');        array_multisort($worker_record_sort, SORT_DESC, $worker_forward_sort, SORT_DESC, $worker_rank);        $worker_rank_chart = array();        foreach ($worker_rank as $r){            //员工列表排行            $worker_rank_chart['name'][] = self::getNickname($r['username'],3,2) ;            $worker_rank_chart['record'][] = $r['all_record'];        }        //团队数据        $team_data = array();        foreach ($worker_data as $w1) {            $team_id = $w1['team'];            $team_info = $team_list[$team_id];            if ($team_info) {                if (isset($team_data[$team_id])) {                    $old_data = $team_data[$team_id];                    $old_data['all_fans'] += $w1['all_fans'];                    $old_data['all_record'] += $w1['all_record'];                    $old_data['all_fee'] += $w1['all_fee'];                    $old_data['all_scansum'] += $w1['all_scansum'];                    $old_data['all_forward'] += $w1['all_forward'];                    $old_data['all_refundfee'] += $w1['all_refundfee'];                    $old_data['all_refund'] += $w1['all_refund'];                    $team_data[$team_id] = $old_data;                } else {                    $team_data[$w1['team']] = [                        'company' =>  $team_info['company'],                        'name' => $team_info['name'],                        'all_fans' => $w1['all_fans'],                        'all_record' => $w1['all_record'],                        //'all_recordzx' => $w1['all_recordzx'],                        //'all_recordxx' => $w1['all_recordxx'],                        'all_fee' => $w1['all_fee'],                        'all_scansum' => $w1['all_scansum'],                        'all_forward' => $w1['all_forward'],                        'all_refundfee' => $w1['all_refundfee'],                        'all_refund' => $w1['all_refund'],                    ];                }            } else {                if (isset($team_data[0])) {                    $old_data = $team_data[0];                    $old_data['all_fans'] += $w1['all_fans'];                    $old_data['all_record'] += $w1['all_record'];                    $old_data['all_fee'] += $w1['all_fee'];                    $old_data['all_scansum'] += $w1['all_scansum'];                    $old_data['all_forward'] += $w1['all_forward'];                    $old_data['all_refundfee'] += $w1['all_refundfee'];                    $old_data['all_refund'] += $w1['all_refund'];                    $team_data[$team_id] = $old_data;                } else {                    $team_data[0] = [                        'company' => 0,                        'name' => '无队名',                        'all_fans' => $w1['all_fans'],                        'all_record' => $w1['all_record'],                        //'all_recordzx' => $w1['all_recordzx'],                        //'all_recordxx' => $w1['all_recordxx'],                        'all_fee' => $w1['all_fee'],                        'all_scansum' => $w1['all_scansum'],                        'all_forward' => $w1['all_forward'],                        'all_refundfee' => $w1['all_refundfee'],                        'all_refund' => $w1['all_refund'],                    ];                }            }        }        if($system['is_multiple_merchants'] && $config['showshop'] > 0) {            $select_company =$config['showshop'];            $othercompany = intval(db_fetchcolumn('SELECT COUNT(*) FROM ' . tablename(t_record) . " as r                        left join " . tablename(t_worker) . " as w on r.workerid = w.uid and r.themeid = w.themeid                        WHERE  r.themeid ='{$themeid}' and ({$ispay_r} {$xuni_show_r}) and (w.company != '{$select_company}' and w.company !=0) " . $addtime_where_r));            $team_data[-1] = [                'company' => 0,                'name' => '联盟',                'all_fans' => 0,                'all_record' => $othercompany,                'all_fee' => 0,                'all_scansum' =>0,                'all_forward' => 0,                'all_refundfee' => 0,                'all_refund' => 0            ];        }        if ($is_multiple_merchants) {    //开启异业联盟            //商家排名            $shangjia_data = array();            if ($shangjia_list) {                foreach ($worker_data as $t) {                    $company = $t['company'];//                    dump($company);//                    dump($t['all_record']);                    $shangjia_info = $shangjia_list[$company];                    if ($shangjia_info) {                        if (isset($shangjia_data[$company])) {                            $old_data = $shangjia_data[$company];                            $old_data['all_fans'] += $t['all_fans'];                            $old_data['all_record'] += $t['all_record'];                            $old_data['all_fee'] += $t['all_fee'];                            $old_data['all_scansum'] += $t['all_scansum'];                            $old_data['all_forward'] += $t['all_forward'];                            $old_data['all_refundfee'] += $t['all_refundfee'];                            $old_data['all_refund'] += $t['all_refund'];                            $shangjia_data[$company] = $old_data;                        } else                            $shangjia_data[$company] = [                                'name' => $shangjia_info['name'],                                'all_fans' => $t['all_fans'],                                'all_record' => $t['all_record'],                                'all_fee' => $t['all_fee'],                                'all_scansum' => $t['all_scansum'],                                'all_forward' => $t['all_forward'],                                'all_refundfee' => $t['all_refundfee'],                                'all_refund' => $t['all_refund'],                            ];                    } else {                        if (isset($shangjia_data[0])) {                            $old_data = $shangjia_data[0];                            $shangjia_data[0] = [                                'all_fans' => $old_data['all_fans'] + $t['all_fans'],                                'all_record' => $old_data['all_record'] + $t['all_record'],                                //'all_recordzx' => $old_data['all_recordzx']+$t['all_recordzx'],                                //'all_recordxx' => $old_data['all_recordxx']+$t['all_recordxx'],                                'all_fee' => $old_data['all_fee'] + $t['all_fee'],                                'all_scansum' => $old_data['all_scansum'] + $t['all_scansum'],                                'all_forward' => $old_data['all_forward'] + $t['all_forward'],                                'all_refundfee' => $old_data['all_refundfee'] + $t['all_refundfee'],                                'all_refund' => $old_data['all_refund'] + $t['all_refund'],                            ];                        } else {                            $shangjia_data[0] = [                                'name' => '无名',                                'all_fans' => $t['all_fans'],                                'all_record' => $t['all_record'],//                                'all_recordzx' => $t['all_recordzx'],//                                'all_recordxx' => $t['all_recordxx'],                                'all_fee' => $t['all_fee'],                                'all_scansum' => $t['all_scansum'],                                'all_forward' => $t['all_forward'],                                'all_refundfee' => $t['all_refundfee'],                                'all_refund' => $t['all_refund']                            ];                        }                    }                }            }            $rank_data = $shangjia_data;        } else {            $rank_data = $team_data;        }        $record_sort = array_column($rank_data, 'all_record');        $forward_sort = array_column($rank_data, 'all_forward');        array_multisort($record_sort, SORT_DESC, $forward_sort, SORT_DESC, $rank_data);        if ($need_new == 1) {            $cache_array['rank_data'] = $rank_data;        }        if (count($rank_data) > 10) {            $team_rank_array = array_slice(array_values($rank_data), 0, 10);        } else {            $team_rank_array = array_values($rank_data);        }        $team_rank = array();        foreach ($team_rank_array as $t) {            if($t['name']!='无队名'||($t['name']=='无队名'&&$t['all_record']>0)){                $team_rank['name'][] = $t['name'];                $team_rank['record'][] = $t['all_record'];            }        }        if ($need_new == 1) {            $cache_array['all_data'] = $all_data;            $cache_array['worker_rank'] = $worker_rank;            $cache_array['worker_rank_chart'] = $worker_rank_chart;            $cache_array['team_rank'] = $team_rank;            $cache_array['team_list'] = $team_rank_array;            $cache_array['lasttime'] = time();        }    }    //最新浏览//    if($return_cache==1&&isset($settings['browse_list'])){//        $browse_list = $settings['browse_list'];//    }else{    $browse_list = self::newBrowse($theme_r,$start_time,$end_time);//        if($need_new==1){//            $cache_array['browse_list'] = $browse_list;//        }//    }    if($cache_array&&$need_new==1){        $result['cache'] = 0;        cache_write($data_cachekey,$cache_array);    }elseif($need_new==0){        $result['cache'] = 0;    }else{        $result['cache'] = 1;    }    $result['all_data'] = $all_data;    $result['hour_data'] = $hour_array;    $result['worker_rank'] = $worker_rank;    $result['worker_rank_chart'] = $worker_rank_chart;    $result['team_list'] = $team_rank_array;    $result['team_rank'] = $team_rank;    $result['browse_list'] = $browse_list;    $result['ratio_data'] = $ratio_data;    $result['order_list'] = $order_list;    $result['time'] = time();    return_json(0,'',$result);}//通用数据
}function baseData($themeid,$system,$data_cachekey){   // cache_delete($data_cachekey);    $theme = Theme::getThemeById($themeid);    $config = Theme::getConfig($themeid);    if (empty($shopname)){        if (empty($theme['jubf'])){            $shopname = $theme['title'];        }else{            $shopname = $theme['jubf'];        }    }    $result = Fans::get_form_count($system,$config,$themeid,'');    //////////////    //表单二    if(isset($result['options2'])&&!empty($result['options2'])){        $ratio_array['address'] = $config['address'];    }    //表单三    if(isset($result['options3'])&&!empty($result['options3'])){        $ratio_array['formtwo'] = $config['formtwo'];    }    //表单五    if(isset($result['options5'])&&!empty($result['options5'])){        $ratio_array['shops'] = $config['shops'];    }    //客户身份    if($config['maxcountall']>1 || $config['maxcountall2']>1 || $config['maxcountall3']>1){        $ratio_array['tuan'] = '客户身份';    }    //是否开启预售    if ($config['yukuan'] > 0 && TIMESTAMP > $config['yukuantime']){        $ratio_array['yushou'] = '预售统计';    }    //是否开启分销    if($system['fenxiao01'] >0 ){        $ratio_array['fenxiao'] = '分销统计';    }    //没有类型 默认显示订单状态    if(empty($ratio_array)){        $ratio_array['order'] = '订单状态';    }    if($_COOKIE['ratio_type']){        $ratio_type = $_COOKIE['ratio_type'];    }else{        reset($ratio_array);        $ratio_type =  key($ratio_array );    }    $rank_type =  1;    if($_COOKIE['rank_type']){        $rank_type = $_COOKIE['rank_type'];    }    $alert_status =  1;    if($_COOKIE['alert_status']){        $alert_status = $_COOKIE['alert_status'];    }    $res_system = [        'softmode' => $system['softmode'],        'wxapp' => $system['wxapp'],        'is_multiple_merchants' => $system['is_multiple_merchants'],        'adminpass'  => $system['adminpass'],    ];    $res_config = [        'softmode' => $config['softmode'],        'workerpass' => $config['workerpass'],        'indexurl' => $config['indexurl'],        'indexurlxcx' => $config['indexurlxcx'],        'addworkerurl' =>$config['addworkerurl'],        'addworkerurlxcx' => $config['addworkerurlxcx']    ];    $rank_array = [        'deal' =>  '粉丝交易Top10',        'recommend' =>  '粉丝推荐Top10',        'help' =>  '粉丝助力Top10',        'tuan' => '团长排名Top10',        'comm' => '红包排名Top10'    ];    //H5 链接地址    // $h5_code_url =  $_G['url_scheme'] . DOMAIN0 . '/web/index.php?c=site&a=entry&do=qr&m='.MODULE_NAME.'&url='.urlencode($config['indexurl']);    $h5_code_url = QRURLNEW.urlencode($config['indexurl']);    return [        'h5_code_url' => $h5_code_url,        'shopname' => $shopname,        'themeid'  => $themeid,        'module_name' => MODULE_NAME,        'system' => $res_system,        'config' => $res_config,        'yxurl' => self::baiduAudio(),        'ratio_array' => $ratio_array,        'rank_array' => $rank_array,        'ratio_type' => $ratio_type,        'rank_type' => $rank_type,        'alert_status' => $alert_status,    ];}//小时详情数据function hourInfo($theme,$is_multiple_merchants,$alldata_settings,$all_where,$end_hour,$target_type,$target_id,$field_type){    $field_types = ['record','recordzx','recordxx','newfans','scansum','forward'];    $start = strtotime('-7 hours',strtotime($end_hour));    $has_before = 1;     if($start<=$theme['begintime']){         $start = $theme['begintime'];         $has_before = 0;     }     $now_date = substr($end_hour,5,2).'月'.substr($end_hour,8,2).'日';     $has_after = 0;     $max_end_hour = $theme['endtime'];     if(time()<$theme['endtime']){         $max_end_hour = time();     }     if(strtotime($end_hour)<$max_end_hour){         $has_after = 1;     }    $date = [];    $return_hour = [];    for ($i=$start; $i<=strtotime($end_hour); $i+=3600)  //3600秒是按每小时生成一条，如果按天或者月份换算成秒即可    {        $hour = date('Y-m-d H',$i).':00:00';        $date[] = $hour;        $return_hour[] =  date('G', strtotime($hour)).":00";    }    if(!in_array($field_type,$field_types)){        $field_type = 'record';    }    $hour_where = " and hour>'{$date[0]}' and hour<='{$end_hour}'";   //24小时前开始时间    //$end_hour_data = end($hour_list);    $worker_list = $alldata_settings['worker_list'];    $team_list = $alldata_settings['team_list'];    $shangjia_list = $alldata_settings['shangjia_list'];    $team_where = '';    if($target_type=='team'){        if (strpos($target_id, '_') !== false) {              $company_team = explode('_',$target_id);              $team_id =  $company_team[1];              $target_id = $company_team[0];        }        $company_id = $target_id;        if($target_id>-1){            $workerids = '';            foreach ($worker_list as $w){                if($target_id==$w['company']){                    $workerids.= $w['uid'].',';                }            }            if($workerids){                $workerids = rtrim($workerids,",");                $team_where = " and workerid in ({$workerids})";            }else{                $team_where = ' and workerid = 0';            }        }    }    if($target_type=='worker'){        if (strpos($target_id, '_') !== false) {            $company_team = explode('_',$target_id);            $target_id = $company_team[1];            $company_id = $company_team[0];            $team_id =  $company_team[1];        }        if($target_id>-1){            $workerids = '';            foreach ($worker_list as $w){                if($target_id==$w['team']){                    $workerids.= $w['uid'].',';                }            }            if($workerids){                $workerids = rtrim($workerids,",");                $team_where = " and workerid in ({$workerids})";            }else{                $team_where = ' and workerid = 0';            }        }    }    $hour_sql = "SELECT hour,workerid,{$field_type} FROM " . tablename(t_workerreport) . " WHERE {$all_where} {$hour_where} {$team_where} and {$field_type}>0";    $hour_list = db_select($hour_sql);    $has_workerid_array = array();    $has_team_array = array();    $has_company_array = array();    $worker_data = array();    $team_data = array ();    $shangjia_data = array ();    $themeid = DAPING_THEMEID;    foreach ($hour_list as $v){        $hour = $v['hour'];        $worker_info =  $worker_list[$themeid.'_'.$v['workerid']];        if ($worker_info) {      //存在员工             $worker_name = $worker_info['username'];             $team  = $worker_info['team'];             $company = $worker_info['company'];        }else{             $worker_name = '未归属';             $v['workerid'] = 0;             $team = 0;             $company = 0;        }        $v['name'] = $worker_name;        $v['team'] = $team;        $v['company'] = $company;        $worker_data[$v['hour'].'_'.$v['workerid']] = $v;        if(!in_array($v['workerid'],$has_workerid_array,true)){            $has_workerid_array[] = $v['workerid'];        }        $team_info =  $team_list[$team];        if ($team_info) {            $key = $hour.'_'.$company.'_'.$team;            if (isset($team_data[$key])) {                $old_data = $team_data[$key];                $old_data[$field_type] += $v[$field_type];                $team_data[$key] = $old_data;            } else {                $team_data[$key] = [                    'company' => $company,                    'hour' => $hour,                    $field_type => $v[$field_type]                ];            }        } else {            $key = $hour.'_'.$company.'_0';            if (isset($team_data[$key])) {                $old_data = $team_data[$key];                $old_data[$field_type] += $v[$field_type];                $team_data[$key] = $old_data;            } else {                $team_data[$key] = [                    'company' => $company,                    'hour' => $hour,                    $field_type => $v[$field_type],                ];            }        }        if(!in_array($company.'_'.$team,$has_team_array,true)){            $has_team_array[] =$company.'_'.$team;        }        if($is_multiple_merchants){            $company_info =  $shangjia_list[$company];            if ($company_info) {                $key = $hour.'_'.$company;                if (isset($shangjia_data[$key])) {                    $old_data = $shangjia_data[$key];                    $old_data[$field_type] += $v[$field_type];                    $shangjia_data[$key] = $old_data;                } else {                    $shangjia_data[$key] = [                        'company' => $company,                        'hour' => $hour,                        $field_type => $v[$field_type]                    ];                }            } else {                $key = $hour.'_0';                if (isset($shangjia_data[$key])) {                    $old_data = $shangjia_data[$key];                    $old_data[$field_type] += $v[$field_type];                    $shangjia_data[$key] = $old_data;                } else {                    $shangjia_data[$key] = [                        'company' => $company,                        'hour' => $hour,                        $field_type => $v[$field_type],                    ];                }            }            if(!in_array($company,$has_company_array,true)){                $has_company_array[] = $v['company'];            }        }    }    $all_hour_data = array();    if($target_type=='worker'|| $target_type=='all_worker'){        foreach ($has_workerid_array as  $w1){            $worker_info = $worker_list[$w1];            if($worker_info){                $team = $worker_info['team'];                $company = $worker_info['company'];                $name =  $worker_info['username'];            }else{                $team = 0;                $company = 0;                $name = '未归属';            }            $hour_data = array();            $team_info =  $team_list[$team];            if($team_info){                $team_name = $team_info['name'];            }else{                $team_name = '无队名';            }            $hour_data['team_name'] = mb_substr($team_name,0,6);            if($is_multiple_merchants==1){                $shangjia_info =  $shangjia_list[$company];                if($shangjia_info){                    $shangjia_name = $shangjia_info['name'];                }else{                    $shangjia_name = '无名';                }                $hour_data['shangjia_name'] =mb_substr($shangjia_name,0,6) ;            }            $hour_data['worker_name'] = mb_substr($name,0,6);            foreach ($date as $d){                $hour = date('G', strtotime($d)).":00";;                if(isset($worker_data[$d.'_'.$w1])){                    $hour_data[$hour] = $worker_data[$d.'_'.$w1][$field_type];                }else{                    $hour_data[$hour] = 0;                }            }            $all_hour_data[] = $hour_data;        }        if($is_multiple_merchants==1){            $field_array[] = '商家';        }         $field_array[] = '团队';        $field_array[] = '员工';    }    else if($target_type=='team'||$target_type=='all_team'){        foreach ($has_team_array as  $t1){            $company_team = explode('_',$t1);            $company =  $company_team[0];            $team =  $company_team[1];            $hour_data = array();            $team_info =  $team_list[$team];            if($team_info){                $name = $team_info['name'];            }else{                $name = '无队名';            }            if($is_multiple_merchants==1){                $shangjia_info =  $shangjia_list[$company];                if($shangjia_info){                    $shangjia_name = $shangjia_info['name'];                }else{                    $shangjia_name = '无名';                }                $hour_data['shangjia_name'] = mb_substr($shangjia_name,0,6);            }            $hour_data['team_name'] = mb_substr($name,0,6);            $hour_data['team'] = $team;            $hour_data['company'] = $company;            foreach ($date as $d){                $hour = date('G', strtotime($d)).":00";;                if(isset($team_data[$d.'_'.$t1])){                    $hour_data[$hour] = $team_data[$d.'_'.$t1][$field_type];                }else{                    $hour_data[$hour] = 0;                }            }            $all_hour_data[] = $hour_data;        }        if($is_multiple_merchants==1){            $field_array[] = '商家';        }        $field_array[] = '团队';    } else if($target_type=='shangjia'||$target_type=='all_shangjia') {        foreach ($has_company_array as  $t1){            $shangjia_info =  $shangjia_list[$t1];            if($shangjia_info){                $name = $shangjia_info['name'];            }else{                $name = '无名';            }            $hour_data = array();            $hour_data['company'] = $t1;            $hour_data['shangjia_name'] = $name;            foreach ($date as $d){                $hour = date('G', strtotime($d)).":00";;                if(isset($shangjia_data[$d.'_'.$t1])){                    $hour_data[$hour] = $shangjia_data[$d.'_'.$t1][$field_type];                }else{                    $hour_data[$hour] = 0;                }            }            $all_hour_data[] = $hour_data;        }        $field_array[] = '商家';    }    $return_data['field']  = $field_array;    $return_data['hour'] = $return_hour;    $return_data['list'] = $all_hour_data;    $return_data['type'] = $target_type;    $return_data['company_id'] = $company_id;    $return_data['team_id'] = $team_id;    $return_data['field_type'] = $field_type;    $return_data['has_before'] = $has_before;    $return_data['has_after'] = $has_after;    $return_data['now_date'] = $now_date;    return $return_data;}//最新订单function orderList($shangjia_list,$team_list,$worker_list,$all_where,$is_multiple_merchants){    //数据放入缓存    $limit = 10;    $order_sql = "SELECT id,themeid,mobile,addtime,avatar,username,nickname,workerid,status FROM " . tablename ( t_record ) . "                      WHERE {$all_where}  order by addtime desc limit {$limit}";    $new_order = db_select ($order_sql);    //数据放入缓存    foreach ($new_order as $index => $item) {        //$new_order[$index]['is_new'] = 1;        $worker_info = $worker_list[$item['themeid'].'_'.$item['workerid']];        if(!$worker_info){            $worker_info['selling_agent'] = 0;            $worker_info['level'] = 3;            $worker_info['username'] = '未归属';        }        if($is_multiple_merchants){ //异业            $team_info = $shangjia_list[$worker_info['company']];        }else{            $team_info = $team_list[$worker_info['team']];        }        $dui_name = $team_info['name']?$team_info['name']:'无名';        if (strlen($item['mobile'])==11){            $new_order[$index]['mobile']=substr($item['mobile'] , 0 , 3).'****'.substr($item['mobile'] , -4);        }        $new_order[$index]['datetime']=date('Y/n/j H:i:s',$item['addtime']);        $new_order[$index]['teamname'] =  mb_substr($dui_name,0,10);        if ($worker_info['selling_agent']==1 && $worker_info['level']==4){    //代理            // $workerinfo= Worker::getThemeWorkerByUid($worker_info['superior'],$themeid);            $workerinfo = $worker_list[$item['superior']];            $wkname = $workerinfo['username'];            $new_order[$index]['wkname']=$team_info['name']."-".$workerinfo['username'].'-'.$item['username'];        }else{            $new_order[$index]['wkname']= $worker_info['username'];        }        if($item['status']==3&&empty($item['avatar'])){            $new_order[$index]['avatar'] = "https://css2020.yixuan.net/2020css/yx2020/images/question.png";        }        $new_order[$index]['datetime']=date('Y/n/j H:i:s',$item['addtime']);    }    $orderlist = $new_order;    return $orderlist;}//最新浏览记录function newBrowse($theme_r,$start_time,$end_time){    //返回最大id    $where = " {$theme_r} AND r.type = 1 AND r.uid>0 ";    if($start_time&&$end_time){        $where .= " AND r.create_time>='{$start_time}' AND r.create_time < '{$end_time}'";    }    $where .= " AND f.nickname!='新用户' AND f.nickname!='微信用户' and f.nickname!='不在活动地区' AND f.avatar IS NOT NULL and f.avatar != '' and f.avatar != 'https://css2020.yixuan.net/2020css/yx2020/images/question.png'";    $browse_sql ="SELECT r.id,r.uid,r.create_time,r.standing_time,f.avatar,f.nickname,f.username,f.mobile                  FROM ". tablename(t_userdata_record)." r                   LEFT JOIN " . tablename(t_fans) . " f on r.uid=f.uid and r.themeid = f.themeid                   WHERE NOT EXISTS (SELECT 1 FROM ".tablename(t_userdata_record)." r2 WHERE r.uid = r2.uid AND r2.type=1 AND r.id < r2.id)                  AND ".$where."  ORDER BY r.id DESC LIMIT 10";      // WHERE  NOT EXISTS (SELECT count(1) FROM ".tablename(t_userdata_record)." r2 WHERE r.uid = r2.uid AND r2.type=1 AND r.id < r2.id)    $new_browse = db_select ($browse_sql);    $browse_list = array();    foreach ($new_browse as $b){         if(time()-strtotime($b['create_time'])>600&&$b['standing_time']==0){            $b['standing_time'] = 10;         }         $b['nickname'] = self::getNickname($b['nickname'],4);         $b['create_time'] = substr($b['create_time'],11);         $browse_list[] = $b;    }    return $browse_list;}//占比function ratioData($system,$config,$themeid,$all_where,$addtime_where,$ratio_type){    $result = Fans::get_form_count($system,$config,$themeid,$addtime_where);    if($ratio_type=='all'){        if($config['address']&&$result['options2']){            $ratio_array['address'] = $result['options2'];        }        //表单三        if($config['formtwo']&&$result['options3']){            $ratio_array['formtwo'] = $result['options3'];        }        //表单五        if($config['shops']&&$result['options5']){            $ratio_array['shops'] = $result['options5'];        }        if($config['maxcountall']>1 || $config['maxcountall2']>1 || $config['maxcountall3']>1) {            $iden_sql = "SELECT  COUNT(CASE WHEN type=0 and status>0 THEN 1  END) AS tuan_num,                                  COUNT(CASE WHEN type=1 and status>0 THEN 1  END) AS member_num,                                  COUNT(CASE WHEN type=9 and status>0 THEN 1 END)  AS  selfbuy_num                                   FROM " . tablename(t_record) . " WHERE {$all_where} {$addtime_where}";            $iden_data = db_find($iden_sql);            //客户身份            $ratio_array['tuan'] = [                ['name' => '团长', 'value' => $iden_data['tuan_num']],                ['name' => '团员', 'value' => $iden_data['member_num']],                ['name' => '单买', 'value' => $iden_data['selfbuy_num']]            ];        }        //是否开启预售        if ($config['yukuan'] > 0 && TIMESTAMP > $config['yukuantime']){            $yushou_data_sql  =  "SELECT  sum((case when type = 8 and status > 0  and status!=3  then 1 else 0 end)) as not_quankuan,                                          sum((case when type!=8 and fee<>'{$config['yukuan']}' and status!=3 and status > 0   then 1  else 0 end)) as bu_quankuan,                                          sum((case when type!=8 and fee='{$config['yukuan']}' and status!=3 and status > 0   then 1  else 0 end)) as pay_quankuan                                          FROM ". tablename ( t_record ) ." WHERE {$all_where} {$addtime_where}";            $yushou_data = db_find($yushou_data_sql);            $ratio_array['yushou'] =  [                ['name' => '未补款','value'=>$yushou_data['not_quankuan']],                ['name' => '已补款','value'=>$yushou_data['bu_quankuan']],                ['name' => '全款','value'=>$yushou_data['pay_quankuan']]            ];        }        //是否开启分销        if($system['fenxiao01'] >0 ){            $fx_data_sql  =  "SELECT                                       sum((case when type=0 and status = 1 then fee  else 0 end)) as first_tuan,                                      sum((case when type=1 and status = 1 then fee  else 0 end)) as first_fx,                                      sum((case when type=2 and status = 1 then fee  else 0 end)) as second_fx,                                       sum((case when type=3 and status = 1 then fee  else 0 end)) as third_fx,                                      sum((case when type=4 and status = 1 then fee  else 0 end)) as zhuanfa_fx,                                      sum((case when type=5 and status = 1 then fee  else 0 end)) as read_fx,                                      sum((case when type=6 and status = 1 then fee  else 0 end)) as worker_tixian,                                      sum((case when type=7 and status = 1 then fee  else 0 end)) as yaoyiyao_fx,                                      sum((case when type=8 and status = 1 then fee  else 0 end)) as buyukuang,                                      sum((case when type=9 and status = 1 then fee  else 0 end)) as alone_buy,                                              sum((case when type=10 and status = 1 then fee  else 0 end)) as enter_link,                                       sum((case when type=11 and status = 1 then fee  else 0 end)) as self_apply,                                         sum((case when type=12 and status = 1 then fee  else 0 end)) as agent_fx,                                           sum((case when type=15 and status = 1 then fee  else 0 end)) as extra_reissue,                                       sum((case when type=99 and status = 99 then fee  else 0 end)) as hand_tx                                      FROM ". tablename ( t_comm ) ." WHERE {$all_where} {$addtime_where}";            $fx_data = db_find($fx_data_sql);            if($fx_data['first_tuan']>0){                $fenxiao[] =  ['name' => '一级分销','value'=>$fx_data['first_tuan']];            }            if($fx_data['second_fx']>0){                $fenxiao[] =  ['name' => '二级分销','value'=>$fx_data['second_fx']];            }            if($fx_data['third_fx']>0){                $fenxiao[] =  ['name' => '三级分销','value'=>$fx_data['third_fx']];            }            if($fx_data['zhuanfa_fx']>0){                $fenxiao[] =  ['name' => '转发红包','value'=>$fx_data['zhuanfa_fx']];            }            if($fx_data['read_fx']>0){                $fenxiao[] =  ['name' => '阅读红包','value'=>$fx_data['read_fx']];            }            if($fx_data['worker_tixian']>0){                $fenxiao[] =  ['name' => '员工提现','value'=>$fx_data['worker_tixian']];            }            if($fx_data['yaoyiyao_fx']>0){                $fenxiao[] =  ['name' => '摇一摇红包','value'=>$fx_data['yaoyiyao_fx']];            }            if($fx_data['buyukuang']>0){                $fenxiao[] =  ['name' => '补余款','value'=>$fx_data['buyukuang']];            }            if($fx_data['alone_buy']>0){                $fenxiao[] =  ['name' => '单买','value'=>$fx_data['alone_buy']];            }            if($fx_data['enter_link']>0){                $fenxiao[] =  ['name' => '进入链接','value'=>$fx_data['enter_link']];            }            if($fx_data['self_apply']>0){                $fenxiao[] =  ['name' => '自己报名','value'=>$fx_data['self_apply']];            }            if($fx_data['agent_fx']>0){                $fenxiao[] =  ['name' => '代理提成','value'=>$fx_data['agent_fx']];            }            if($fx_data['extra_reissue']>0){                $fenxiao[] =  ['name' => '额外补发','value'=>$fx_data['extra_reissue']];            }            if($fx_data['hand_tx']>0){                $fenxiao[] =  ['name' => '手工提现','value'=>$fx_data['hand_tx']];            }            $ratio_array['fenxiao'] = $fenxiao;        }        $ratio = $ratio_array;    }else{        switch ($ratio_type){            case 'address':                $ratio = $result['options2'];                break;            case 'formtwo':                $ratio = $result['options3'];                break;            case 'shops':                $ratio = $result['options5'];                break;            case 'tuan':    //团员身份                $iden_sql = "SELECT  COUNT(CASE WHEN type=0 and status>0 THEN 1  END) AS tuan_num,                              COUNT(CASE WHEN type=1 and status>0 THEN 1  END) AS member_num,                              COUNT(CASE WHEN type=9 and status>0 THEN 1 END)  AS  selfbuy_num                               FROM ".tablename(t_record)." WHERE {$all_where} {$addtime_where}";                $iden_data = db_find($iden_sql);                $ratio = [                    ['name' => '团长','value'=>$iden_data['tuan_num']],                    ['name' => '团员','value'=>$iden_data['member_num']],                    ['name' => '单买','value'=>$iden_data['selfbuy_num']]                ];                break;            case 'yushou':                $yushou_data_sql  =  "SELECT  sum((case when type = 8 and status > 0  and status!=3  then 1 else 0 end)) as not_quankuan,                                          sum((case when type!=8 and fee<>'{$config['yukuan']}' and status!=3 and status > 0   then 1  else 0 end)) as bu_quankuan,                                          sum((case when type!=8 and fee='{$config['yukuan']}' and status!=3 and status > 0   then 1  else 0 end)) as pay_quankuan                                          FROM ". tablename ( t_record ) ." WHERE {$all_where} {$addtime_where}";                $yushou_data = db_find($yushou_data_sql);                $ratio = [                    ['name' => '未补款','value'=>$yushou_data['not_quankuan']],                    ['name' => '已补款','value'=>$yushou_data['bu_quankuan']],                    ['name' => '全款','value'=>$yushou_data['pay_quankuan']]                ];                break;            case 'fenxiao':                $fx_data_sql  =  "SELECT                                       sum((case when type=0 and status = 1 then fee  else 0 end)) as first_tuan,                                      sum((case when type=1 and status = 1 then fee  else 0 end)) as first_fx,                                      sum((case when type=2 and status = 1 then fee  else 0 end)) as second_fx,                                       sum((case when type=3 and status = 1 then fee  else 0 end)) as third_fx,                                      sum((case when type=4 and status = 1 then fee  else 0 end)) as zhuanfa_fx,                                      sum((case when type=5 and status = 1 then fee  else 0 end)) as read_fx,                                      sum((case when type=6 and status = 1 then fee  else 0 end)) as worker_tixian,                                      sum((case when type=7 and status = 1 then fee  else 0 end)) as yaoyiyao_fx,                                      sum((case when type=8 and status = 1 then fee  else 0 end)) as buyukuang,                                      sum((case when type=9 and status = 1 then fee  else 0 end)) as alone_buy,                                              sum((case when type=10 and status = 1 then fee  else 0 end)) as enter_link,                                       sum((case when type=11 and status = 1 then fee  else 0 end)) as self_apply,                                         sum((case when type=12 and status = 1 then fee  else 0 end)) as agent_fx,                                           sum((case when type=15 and status = 1 then fee  else 0 end)) as extra_reissue,                                       sum((case when type=99 and status = 99 then fee  else 0 end)) as hand_tx                                      FROM ". tablename ( t_comm ) ." WHERE {$all_where} {$addtime_where}";                $fx_data = db_find($fx_data_sql);                if($fx_data['first_tuan']>0){                    $ratio[] =  ['name' => '一级分销','value'=>$fx_data['first_tuan']];                }                if($fx_data['second_fx']>0){                    $ratio[] =  ['name' => '二级分销','value'=>$fx_data['second_fx']];                }                if($fx_data['third_fx']>0){                    $ratio[] =  ['name' => '三级分销','value'=>$fx_data['third_fx']];                }                if($fx_data['zhuanfa_fx']>0){                    $ratio[] =  ['name' => '转发红包','value'=>$fx_data['zhuanfa_fx']];                }                if($fx_data['read_fx']>0){                    $ratio[] =  ['name' => '阅读红包','value'=>$fx_data['read_fx']];                }                if($fx_data['worker_tixian']>0){                    $ratio[] =  ['name' => '员工提现','value'=>$fx_data['worker_tixian']];                }                if($fx_data['yaoyiyao_fx']>0){                    $ratio[] =  ['name' => '摇一摇红包','value'=>$fx_data['yaoyiyao_fx']];                }                if($fx_data['buyukuang']>0){                    $ratio[] =  ['name' => '补余款','value'=>$fx_data['buyukuang']];                }                if($fx_data['alone_buy']>0){                    $ratio[] =  ['name' => '单买','value'=>$fx_data['alone_buy']];                }                if($fx_data['enter_link']>0){                    $ratio[] =  ['name' => '进入链接','value'=>$fx_data['enter_link']];                }                if($fx_data['self_apply']>0){                    $ratio[] =  ['name' => '自己报名','value'=>$fx_data['self_apply']];                }                if($fx_data['agent_fx']>0){                    $ratio[] =  ['name' => '代理提成','value'=>$fx_data['agent_fx']];                }                if($fx_data['extra_reissue']>0){                    $ratio[] =  ['name' => '额外补发','value'=>$fx_data['extra_reissue']];                }                if($fx_data['hand_tx']>0){                    $ratio[] =  ['name' => '手工提现','value'=>$fx_data['hand_tx']];                }                break;            case 'order':       //订单数据                $order_sql =  "SELECT  count(case when  status = 0  then 1 end) as not_pay,                          count(case when  status > 0  and status!=3   then 1 end) as pay,                          count(case when  status = -1   then 1 end) as refund,                                count(case when  status=3 then 1 end) as offline  FROM ". tablename ( t_record ) ."                           WHERE {$all_where} {$addtime_where}";                $order_data = db_find($order_sql);                $ratio = [                    ['name' => '未支付','value'=>$order_data['not_pay']],                    ['name' => '已支付','value'=>$order_data['pay']],                    ['name' => '退款','value'=>$order_data['refund']],                    ['name' => '线下','value'=>$order_data['offline']],                ];                break;        }        setcookie('ratio_type',$ratio_type);    }    return $ratio;}//排名function rankData($all_where,$addtime_where,$workerids,$rank_type){    //排行类型    $not_fromuid_where = '';    if($workerids){        $not_fromuid_where = " and fromuid not in ($workerids)";    }    $fans_limit = 10;    $rank_list = array();    if($rank_type=='all'){        //成交        $cj_sql = "SELECT uid,username,nickname,scansum,forward,tuijian FROM " . tablename(t_fans) . " WHERE {$all_where} {$not_fromuid_where} AND  tuijian>0 ORDER BY tuijian DESC,addtime ASC LIMIT {$fans_limit}";        $cj_rank_list = db_select($cj_sql);        if($cj_rank_list){            foreach($cj_rank_list as $k=>$v){                $name = $v['username']?$v['username']:$v['nickname'];                $name = mb_substr($name,-5);                $cj_list['name'][] = $name;                $cj_list['tuijian'][] = $v['tuijian'];                $cj_list['scansum'][] = $v['scansum'];                $cj_list['forward'][] = $v['forward'];                $cj_rank_list[$k]['username'] = $name;            }        }else{            $cj_list['name'][] = [];            $cj_list['tuijian'][] = [];            $cj_list['scansum'][] = [];            $cj_list['forward'][] = [];        }        $rank_list['deal'] = $cj_list;        $rank_list['deal_list'] = $cj_rank_list;        //推荐        $tj_sql = "SELECT uid,username,nickname,scansum,forward,responsum FROM " . tablename(t_fans) . " WHERE {$all_where} {$not_fromuid_where} AND responsum>0  ORDER BY responsum DESC,addtime ASC LIMIT {$fans_limit}";        $tj_rank_list = db_select($tj_sql);        if($tj_rank_list){            foreach($tj_rank_list as $k=>$v){                $name = $v['username']?$v['username']:$v['nickname'];                $name = mb_substr($name,-5);                $tj_list['name'][] = $name;                $tj_list['responsum'][] = $v['responsum'];                $tj_list['scansum'][] = $v['scansum'];                $tj_list['forward'][] = $v['forward'];                $tj_rank_list[$k]['username'] = $name;            }        }else{            $tj_list['name'][] = [];            $tj_list['responsum'][] = [];            $tj_list['scansum'][] = [];            $tj_list['forward'][] = [];        }        $rank_list['recommend'] = $tj_list;        $rank_list['recommend_list'] = $tj_rank_list;        //助力        $zl_sql = "SELECT uid,username,nickname,lightsum FROM " . tablename(t_fans) . " WHERE {$all_where} {$not_fromuid_where} AND lightsum>0 ORDER BY lightsum DESC,addtime ASC LIMIT {$fans_limit}";        $zl_rank_list = db_select($zl_sql);        if($zl_rank_list){            foreach($zl_rank_list as $k=>$v){                $name = $v['username']?$v['username']:$v['nickname'];                $name = mb_substr($name,-5);                $zl_list['name'][] = $name;                $zl_list['lightsum'][] = $v['lightsum'];                $zl_rank_list[$k]['username'] = $name;            }        }else{            $zl_list['name'] = [];            $zl_list['lightsum'] = [];        }        $rank_list['help'] = $zl_list;        $rank_list['help_list'] = $zl_rank_list;        $tuanrank_sql = "SELECT username,nickname,tuannum FROM ".tablename(t_record)."                         WHERE {$all_where} {$addtime_where} and status > 0 and type = 0  ORDER BY tuannum desc,addtime asc limit {$fans_limit}";        $tuanrank_list = db_select ($tuanrank_sql);        if($tuanrank_list){            foreach ($tuanrank_list as $k=>$t){                $tuan_list['name'][] = $t['nickname'];                $tuan_list['tuannum'][] = $t['tuannum'];            }        } else{            $tuan_list['name'][] = [];            $tuan_list['tuannum'][] = [];        }        $rank_list['tuan'] = $tuan_list;        $rank_list['tuan_list'] = $tuanrank_list;        //红包        $comm_sql = "SELECT uid,count(*) as comm_num,sum(fee) as comm_fee  FROM " . tablename(t_comm) . " WHERE {$all_where} and status = 1 GROUP BY uid ORDER BY comm_num DESC,addtime ASC LIMIT {$fans_limit}";        $comm_list = db_select($comm_sql,array(),'uid');        if($comm_list){            $uids = array_keys($comm_list);            $uids_str = '';            if($uids){                $uids_str = implode(',',$uids);            }            $comm_fans = "SELECT uid,username,nickname FROM ".tablename(t_fans)." WHERE uid in ({$uids_str})";            $comm_fans_list = db_select($comm_fans,array(),'uid');            foreach ($comm_list as $k=>$c) {                $fans_info = $comm_fans_list[$k];                $name = $fans_info['username'] ? $fans_info['username'] : $fans_info['nickname'];                $name = mb_substr($name,-5);                $comm_fans_rank['name'][] = $name;                $comm_fans_rank['comm_num'][] = $c['comm_num'];                $comm_fans_rank['comm_fee'][] = $c['comm_fee'];                $comm_list[$k]['username'] = $name;            }        }else{            $comm_fans_rank['name'][] = [];            $comm_fans_rank['comm_num'][] = [];            $comm_fans_rank['comm_fee'][] = [];        }        $rank_list['comm'] = $comm_fans_rank;        $rank_list['comm_list'] = array_values($comm_list);        return $rank_list;    }else{        //粉丝排名  查询全部        if($rank_type<4){            if($addtime_where){      //存在时间段搜索                //查询用户总数据                if($rank_type==1){                    //成交                    $fans_deal_sql = "SELECT fromuid,username,nickname,count(id) as tuijian  FROM ".tablename(t_record)."                                       WHERE {$all_where} {$addtime_where}  and status > 0 and type = 0  GROUP BY fromuid ORDER BY tuijian desc,addtime asc limit 10";                    $fans_deal_list = db_select ($fans_deal_sql,array(),'fromuid');                    if($fans_deal_list){                        foreach ($fans_deal_list as $k => $d){                            $name = $d['username']?$d['username']:$d['nickname'];                            $rank_list['name'][] = $name;                            $rank_list['tuijian'][] = $d['tuijian'];                            $rank_list['scansum'][] = [];                            $rank_list['forward'][] = [];                        }                    }else{                        $rank_list['name'][] = [];                        $rank_list['tuijian'][] = [];                        $rank_list['scansum'][] = [];                        $rank_list['forward'][] = [];                    }                }                if($rank_type==2){                    //推荐                    $fans_respon_sql = "SELECT  fromuid,avatar,nickname,count(id) as responsum FROM ".tablename(t_fans)."                                            WHERE {$all_where} {$addtime_where} {$not_fromuid_where} GROUP BY fromuid  ORDER BY responsum desc,addtime asc limit 10";                    $fans_order_list = db_select ($fans_respon_sql,array(),'fromuid');                    if($fans_order_list){                        foreach ($fans_order_list as $k => $d){                            $name = $d['username']?$d['username']:$d['nickname'];                            $rank_list['name'][] = $name;                            $rank_list['responsum'][] = $d['responsum'];                            $rank_list['scansum'][] = [];                            $rank_list['forward'][] = [];                        }                    }else{                        $rank_list['name'][] = [];                        $rank_list['responsum'][] = [];                        $rank_list['scansum'][] = [];                        $rank_list['forward'][] = [];                    }                }                if($rank_type==3){                    //助力排行                    $fans_friend_sql = "SELECT  fromuid,count(id) as lightsum FROM ".tablename(t_friend)."                                              WHERE {$all_where} {$addtime_where} {$not_fromuid_where} GROUP BY fromuid  ORDER BY lightsum desc,addtime asc limit 10";                    $fans_order_list = db_select ($fans_friend_sql,array(),'fromuid');                    if($fans_order_list){                        //查询                        $uids = array_keys($fans_order_list);                        $uids_str = '';                        if($uids){                            $uids_str = implode(',',$uids);                        }                        $fans_sql = "SELECT uid,avatar,nickname FROM ".tablename(t_fans)." WHERE uid in ({$uids_str}) ";                        $fans_all_list = db_select($fans_sql,array(),'uid');                        foreach ($fans_order_list as $k=>$c){                            $fans_info = $fans_all_list[$k];                            $rank_list['name'][] = $fans_info['nickname'];                            $rank_list['lightsum'][] =  $c['lightsum'];                        }                    }else{                        $rank_list['name'][] = [];                        $rank_list['lightsum'][] = [];                    }                }            }else{     //查询所有数据                switch ($rank_type){                    case 1:                        $field_type = 'tuijian';                        break;                    case 2:                        $field_type = 'responsum';                        break;                    case 3:                        $field_type = 'lightsum';                        break;                    default:                        $field_type = 'tuijian';                        break;                }                $fansrank_sql = "SELECT uid,username,nickname,scansum,forward,{$field_type} FROM " . tablename(t_fans) . " WHERE {$all_where} {$addtime_where} {$not_fromuid_where} AND {$field_type}> 0   ORDER BY {$field_type} DESC,addtime ASC LIMIT {$fans_limit}";                $fans_rank_list = db_select($fansrank_sql);                if($fans_rank_list){                    foreach($fans_rank_list as $k){                        $name = $k['username']?$k['username']:$k['nickname'];                        $rank_list['name'][] = mb_substr($name,-5);                        if($rank_type<3){                            $rank_list['scansum'][] = $k['scansum'];                            $rank_list['forward'][] =  $k['forward'];                        }                        $rank_list[$field_type][] = $k[$field_type];                    }                }else{                    $rank_list['name'][] = [];                    $rank_list[$field_type][] = [];                    $rank_list['scansum'][] = [];                    $rank_list['forward'][] = [];                }                // and nickname<>'新用户'            }        }        if($rank_type == 4){    //团长排名            $tuanrank_sql = "SELECT username,nickname,tuannum FROM ".tablename(t_record)."                         WHERE {$all_where} {$addtime_where} and status > 0 and type = 0  ORDER BY tuannum desc,addtime asc limit 10";            $tuanrank_list = db_select ($tuanrank_sql);            if($tuanrank_list){                foreach ($tuanrank_list as $t){                    $name = $t['username']?$t['username']:$t['nickname'];                    $rank_list['name'][] = mb_substr($name,-5);                    // $rank_list['name'][] = $t['nickname'];                    $rank_list['tuannum'][] = $t['tuannum'];                }            } else{                $rank_list['name'][] = [];                $rank_list['tuannum'][] = [];            }        }        if($rank_type==5){    //红包排名            $comm_order_type = 'comm_num';            $comm_limit = 10;            $comm_sql = "SELECT uid,count(*) as comm_num,sum(fee) as comm_fee  FROM " . tablename(t_comm) . " WHERE {$all_where} {$addtime_where} and status = 1 GROUP BY uid ORDER BY ".$comm_order_type." DESC,addtime ASC LIMIT {$comm_limit}";            $comm_list = db_select($comm_sql,array(),'uid');            if($comm_list){                $uids = array_keys($comm_list);                $uids_str = '';                if($uids){                    $uids_str = implode(',',$uids);                }                $comm_fans = "SELECT uid,username,nickname FROM ".tablename(t_fans)." WHERE uid in ({$uids_str})";                $comm_fans_list = db_select($comm_fans,array(),'uid');                foreach ($comm_list as $k=>$c) {                    $fans_info = $comm_fans_list[$k];                    $name = $fans_info['username'] ? $fans_info['username'] : $fans_info['nickname'];                    $rank_list['name'][] = mb_substr($name, -5);                    $rank_list['comm_num'][] = $c['comm_num'];                    $rank_list['comm_fee'][] = $c['comm_fee'];                }            }else{                $rank_list['name'][] = [];                $rank_list['comm_num'][] = [];                $rank_list['comm_fee'][] = [];            }        }        setcookie('rank_type',$rank_type);    }    return $rank_list;}//员工排行数据function workerRankList($shangjia_list,$team_list,$worker_list,$all_where,$is_multiple_merchants,$workerreport_time_where,$page,$order_field ='all_record',$order_type = 2,$team=-1){       //员工排名    $page_start = ($page-1)*PAGE_LIMIT;    $order_type = $order_type==1?'ASC':'DESC';    $order = $order_field.' '.$order_type;    $team_where = '';    if($team>=0){        $workerids = '';        foreach ($worker_list as $w){            if($team==$w['team']){                $workerids.= $w['uid'].',';            }        }        if($workerids){            $workerids = rtrim($workerids,",");            $team_where = " and workerid in ({$workerids})";        }    }    //查询数量    $workerreport_count = "SELECT count(distinct(workerid)) as count FROM " . tablename ( t_workerreport ) . " WHERE {$all_where} {$workerreport_time_where} {$team_where}";    $count =  db_find($workerreport_count)['count'];    if($count){        $total_page = ceil($count/PAGE_LIMIT);    }else{        $total_page = 1;    }    $workerreport_sql = "SELECT themeid,workerid,sum(newfans) as all_fans,                                        sum(record)-sum(refund) + sum(recordxx) as all_record,                                        sum(fee) as all_fee,                                        sum(scansum) as all_scansum,                                        sum(forward) as all_forward,                                        sum(refundfee) as all_refundfee,                                        sum(refund) as all_refund,                                        sum(recordxx) as all_recordxx,                                        sum(recordzx) as all_recordzx                            FROM " . tablename ( t_workerreport ) . " WHERE {$all_where} {$team_where} {$workerreport_time_where}                             GROUP BY workerid   ORDER BY  {$order},workerid ASC  LIMIT " . $page_start.','. PAGE_LIMIT;    $workerreport =  db_select($workerreport_sql);    foreach ($workerreport as $k=> $v){        $worker_info = $worker_list[$v['themeid'].'_'.$v['workerid']];        if($worker_info) {            if ($is_multiple_merchants) {                $company_info = $shangjia_list[$worker_info['company']];                $team_name = $company_info ? $company_info['name'] : '无名';            } else {                $team_info = $team_list[$worker_info['team']];                $team_name = $team_info ? $team_info['name'] : '无队名';            }        }        $workerreport[$k]['rank'] = (($page-1)*PAGE_LIMIT)+$k+1;        $workerreport[$k]['teamname'] = $team_name;        $workerreport[$k]['username'] = $worker_info['username']? $worker_info['username']:'未归属';    }    return [        'list' => $workerreport,        'total_page' => $total_page    ];}//团队排名function teamRankList($team_list,$all_where,$start_time,$end_time,$page,$order_field ='all_record',$order_type = 2,$company=-1){    $page_start = ($page-1)*PAGE_LIMIT;    $order_type = $order_type==1?'ASC':'DESC';    $order = $order_field.' '.$order_type;    $where = '';    if($company>=0){        $where = " and w.company = $company";    }    $workerreport_time_where = '';    if($start_time&&$end_time){        $workerreport_time_where = " and r.hour>='{$start_time}' and r.hour<'{$end_time}'";    }    //查询数量    $team_count = "SELECT count(distinct(w.team)) as count FROM " . tablename ( t_workerreport ) ." r                    LEFT JOIN ".tablename(t_worker)." w ON  w.{$all_where} and w.uid = r.workerid                    WHERE r.{$all_where}  {$workerreport_time_where} {$where}";    $count =  db_fetchcolumn($team_count);    if($count){        $total_page = ceil($count/PAGE_LIMIT);    }else{        $total_page = 1;    }    $team_sql = "SELECT ifnull(w.team,0) as team,                         sum(r.newfans) as all_fans,                        sum(r.record) as all_record,                        sum(r.fee) as all_fee,                        sum(r.scansum) as all_scansum,                        sum(r.forward) as all_forward,                        sum(r.refundfee) as all_refundfee,                        sum(r.refund) as all_refund,                        sum(r.recordxx) as all_recordxx,                        sum(r.recordzx) as all_recordzx                 FROM " . tablename (t_workerreport) ." r                  LEFT JOIN ".tablename(t_worker)." w ON w.{$all_where} and w.uid = r.workerid                  WHERE r.{$all_where}  {$workerreport_time_where} {$where}                 GROUP BY  w.team   ORDER BY  {$order},w.team ASC  LIMIT " . $page_start.','. PAGE_LIMIT;    $team =  db_select($team_sql);    foreach ($team as $k=> $v){        $team_info = $team_list[$v['team']];        $team_name = $team_info?$team_info['name']:'无队名';        $team[$k]['rank'] = (($page-1)*PAGE_LIMIT)+$k+1;        $team[$k]['teamname'] = $team_name;    }    return [        'list' => $team,        'total_page' => $total_page    ];}//商家排名function shangjiaRankList($shangjia_list,$all_where,$start_time,$end_time,$page,$order_field ='all_record',$order_type = 2){    $page_start = ($page-1)*PAGE_LIMIT;    $order_type = $order_type==1?'ASC':'DESC';    $order = $order_field.' '.$order_type;    $workerreport_time_where = '';    if($start_time&&$end_time){        $workerreport_time_where = " and r.hour>='{$start_time}' and r.hour<'{$end_time}'";    }    //查询数量    $team_count = "SELECT count(distinct(company)) as count FROM " . tablename ( t_worker );    $count =  db_fetchcolumn($team_count);    if($count){        $total_page = ceil($count/PAGE_LIMIT);    }else{        $total_page = 1;    }    $shangjia_sql = "SELECT ifnull(w.company,0) as company,                         ifnull(sum(r.newfans),0) as all_fans,                        ifnull(sum(r.record),0) as all_record,                        ifnull(sum(r.fee),0) as all_fee,                        ifnull(sum(r.scansum),0) as all_scansum,                        ifnull(sum(r.forward),0) as all_forward,                        ifnull(sum(r.refundfee),0) as all_refundfee,                        ifnull(sum(r.refund),0) as all_refund,                        ifnull(sum(r.recordxx),0) as all_recordxx,                        ifnull(sum(r.recordzx),0) as all_recordzx                 FROM " . tablename (t_workerreport) ." r                  LEFT JOIN ".tablename(t_worker)." w ON w.{$all_where} and w.uid = r.workerid                  WHERE r.{$all_where}  {$workerreport_time_where}                  GROUP BY  w.company   ORDER BY  {$order},w.company ASC  LIMIT " . $page_start.','. PAGE_LIMIT;    $shangjia =  db_select($shangjia_sql);    foreach ($shangjia as $k=> $v){        $shangjia_info = $shangjia_list[$v['company']];        $shangjia_name = $shangjia_info?$shangjia_info['name']:'无名';        $shangjia[$k]['rank'] = (($page-1)*PAGE_LIMIT)+$k+1;        $shangjia[$k]['shangjia_name'] = $shangjia_name;    }    return [        'list' => $shangjia,        'total_page' => $total_page    ];}//正在浏览列表function browseList($alldata_settings,$theme_r,$start_time,$end_time,$page,$order_field ='all_record',$order_type = 2){    $page_start = ($page-1)*PAGE_LIMIT;    $order_type = $order_type==1?'ASC':'DESC';    $order = 'r.'.$order_field.' '.$order_type;    $where = " {$theme_r} AND r.type = 1 AND r.uid>0 AND f.nickname!='新用户' AND f.nickname!='微信用户' and f.nickname!='不在活动地区' AND f.status <> -3  AND f.uid>0 AND f.avatar IS NOT NULL AND f.avatar != '' AND f.avatar != 'https://css2020.yixuan.net/2020css/yx2020/images/question.png'";    if($start_time&&$end_time){        $where .= " AND r.create_time>= $start_time AND r.create_time < $end_time";    }    $count_sql = "SELECT count(r.id) FROM ".tablename (t_userdata_record) . " r              LEFT JOIN " . tablename(t_fans) . "  f on r.uid=f.uid and r.themeid = f.themeid               WHERE {$where}";    $count = db_fetchcolumn($count_sql);    if($count){        $total_page = ceil($count/PAGE_LIMIT);    }else{        $total_page = 1;    }    $browse_sql = "SELECT r.id,r.uid,r.workerid,r.link_type,r.create_time,r.type_num,r.standing_time,f.avatar,f.nickname,f.username,f.mobile                    FROM " . tablename(t_userdata_record) . "   r                     LEFT JOIN " . tablename(t_fans) . "  f on r.uid=f.uid and r.themeid = f.themeid                     WHERE ".$where ." order by {$order} LIMIT " . $page_start.','. PAGE_LIMIT;    $browse_list = db_select ($browse_sql);    foreach ($browse_list as $k=>$b){        $browse_list[$k]['nickname'] =   self::getNickname($b['nickname'],8);        $link_type = Userdata::linkType($b['link_type']);        $browse_list[$k]['link_type'] = $link_type['name'];        $worker_name = self::getWorkerName($alldata_settings,$b['workerid']);        $browse_list[$k]['worker_name'] = $worker_name;        if(time()-strtotime($b['create_time'])>600&&$b['standing_time']==0){            $browse_list[$k]['standing_time'] = 10;        }    }    return [        'list' => $browse_list,        'total_page' => $total_page    ];}//粉丝成交排名function fansCjRankList($all_where,$addtime_where,$alldata_settings,$page,$order_field ='tuijian',$order_type = 2){    $page_start = ($page-1)*PAGE_LIMIT;    $order_type = $order_type==1?'ASC':'DESC';    $workerids = $alldata_settings['workerids'];    $order = $order_field.' '.$order_type;    $not_fromuid_where = '';    if($workerids) {        $not_fromuid_where = " and fromuid not in ($workerids)";    }    if($addtime_where){      //存在时间搜索        $where = " AND nickname!='新用户' AND nickname!='微信用户' and nickname!='不在活动地区' AND uid>0 AND avatar IS NOT NULL                  AND avatar != '' AND avatar != 'https://css2020.yixuan.net/2020css/yx2020/images/question.png'";        $fans_count =  "SELECT count(distinct(fromuid)) as count FROM " . tablename ( t_record ) . " WHERE  {$all_where} {$addtime_where} {$not_fromuid_where} and status > 0 and type = 0";        $count =  db_fetchcolumn($fans_count);        $fansrank_sql = "SELECT uid,fromuid,fromuid,workerid,avatar,nickname,count(id) as tuijian  FROM ".tablename(t_record)            ." WHERE {$all_where} {$addtime_where} {$not_fromuid_where} {$where} and status > 0 and type = 0                             GROUP BY fromuid ORDER BY {$order},addtime asc LIMIT ". $page_start.','. PAGE_LIMIT;    }else{        $where = " AND nickname!='新用户' AND nickname!='微信用户' and nickname!='不在活动地区' AND status <> -3  AND uid>0 AND avatar IS NOT NULL                    AND avatar != '' AND avatar != 'https://css2020.yixuan.net/2020css/yx2020/images/question.png'";        $fans_count = "SELECT count(id) as count FROM " . tablename (t_fans) . " WHERE {$all_where}  {$not_fromuid_where} {$where}";        $count =  db_fetchcolumn($fans_count);        $fansrank_sql = "SELECT uid,fromuid,avatar,workerid,nickname,scansum,forward,tuijian FROM " . tablename(t_fans)            . " WHERE {$all_where}  {$not_fromuid_where} {$where}  ORDER BY tuijian DESC,addtime ASC LIMIT " . $page_start.','. PAGE_LIMIT;    }    //查询数量    if($count){        $total_page = ceil($count/PAGE_LIMIT);    }else{        $total_page = 1;    }    $fansrank =  db_select($fansrank_sql);    foreach ($fansrank as $k=> $v){        $fansrank[$k]['rank'] = (($page-1)*PAGE_LIMIT)+$k+1;        $fansrank[$k]['nickname'] =  self::getNickname($v['nickname'],12);        $worker_name = self::getWorkerName($alldata_settings,$v['workerid']);        $fansrank[$k]['worker_name'] = $worker_name;    }    return [        'list' => $fansrank,        'total_page' => $total_page    ];}//粉丝推荐排名function fansTjRankList($all_where,$addtime_where,$alldata_settings,$page,$order_field ='responsum',$order_type = 2){    $page_start = ($page-1)*PAGE_LIMIT;    $order_type = $order_type==1?'ASC':'DESC';    $order = $order_field.' '.$order_type;    $not_fromuid_where = '';    $workerids = $alldata_settings['workerids'];    if($workerids) {        $not_fromuid_where = " and fromuid not in ($workerids)";    }    if($addtime_where){      //存在时间搜索        $where = " AND nickname!='新用户' AND nickname!='微信用户' and nickname!='不在活动地区' AND status <> -3  AND uid>0 AND avatar IS NOT NULL                    AND avatar != '' AND avatar != 'https://css2020.yixuan.net/2020css/yx2020/images/question.png'";        $fans_count =  "SELECT count(distinct(fromuid)) as count FROM " . tablename ( t_fans ) . " WHERE  {$all_where} {$addtime_where} {$not_fromuid_where} {$where}";        $count =  db_fetchcolumn($fans_count);        $fansrank_sql = "SELECT  fromuid,avatar,nickname,workerid,count(id) as responsum FROM ".tablename(t_fans)            ."  WHERE {$all_where} {$addtime_where} {$not_fromuid_where} {$where}                       GROUP BY fromuid ORDER BY {$order},addtime asc LIMIT ". $page_start.','. PAGE_LIMIT;    }else{        $where = " AND nickname!='新用户' AND nickname!='微信用户' and nickname!='不在活动地区' AND status <> -3  AND uid>0 AND avatar IS NOT NULL                    AND avatar != '' AND avatar != 'https://css2020.yixuan.net/2020css/yx2020/images/question.png'";        $fans_count = "SELECT count(id) as count FROM " . tablename (t_fans) . " WHERE {$all_where}  {$not_fromuid_where} {$where}";        $count =  db_fetchcolumn($fans_count);        $fansrank_sql = "SELECT uid,avatar,nickname,workerid,scansum,forward,responsum FROM " . tablename(t_fans)            . " WHERE {$all_where}  {$not_fromuid_where} {$where}  ORDER BY responsum DESC,addtime ASC LIMIT " . $page_start.','. PAGE_LIMIT;    }    //查询数量    if($count){        $total_page = ceil($count/PAGE_LIMIT);    }else{        $total_page = 1;    }    $fansrank =  db_select($fansrank_sql);    foreach ($fansrank as $k=> $v){        $fansrank[$k]['rank'] = (($page-1)*PAGE_LIMIT)+$k+1;        $fansrank[$k]['nickname'] =  self::getNickname($v['nickname'],12);        $worker_name = self::getWorkerName($alldata_settings,$v['workerid']);        $fansrank[$k]['worker_name'] = $worker_name;    }    return [        'list' => $fansrank,        'total_page' => $total_page    ];}//粉丝助力排名function fansZlRankList($all_where,$start_strtotime,$end_strtotime,$alldata_settings,$page,$order_field ='lightsum',$order_type = 2){    $page_start = ($page-1)*PAGE_LIMIT;    $order_type = $order_type==1?'ASC':'DESC';    $order = $order_field.' '.$order_type;    $workerids = $alldata_settings['workerids'];    $not_fromuid_where = '';    if($start_strtotime&&$end_strtotime){      //存在时间搜索        if($workerids) {            $not_fromuid_where = " and d.fromuid not in ($workerids)";        }        $addtime_where = " and d.addtime between $start_strtotime and $end_strtotime";        $where = " AND f.nickname!='新用户' AND f.nickname!='微信用户' and f.nickname!='不在活动地区' AND f.status <> -3  AND f.uid>0 AND f.avatar IS NOT NULL AND f.avatar != '' AND f.avatar != 'https://css2020.yixuan.net/2020css/yx2020/images/question.png'";        $fans_count =  "SELECT count(distinct(d.fromuid)) as count FROM " . tablename ( t_friend ) . " d                        LEFT JOIN ".tablename (t_fans)." f ON d.uid = f.uid AND d.themeid = f.themeid                         WHERE  d.{$all_where} {$addtime_where} {$not_fromuid_where} {$where}";        $count =  db_fetchcolumn($fans_count);        //查询数量        if($count){            $total_page = ceil($count/PAGE_LIMIT);        }else{            $total_page = 1;        }        $fansrank_sql = "SELECT  d.fromuid,count(d.id) as lightsum,f.avatar,f.nickname,d.workerid FROM ".tablename(t_friend) ." d                           LEFT JOIN ".tablename (t_fans)." f ON d.fromuid = f.uid AND d.themeid = f.themeid                          WHERE d.{$all_where} {$addtime_where} {$not_fromuid_where} {$where}                         GROUP BY fromuid ORDER BY {$order},d.addtime asc LIMIT ". $page_start.','. PAGE_LIMIT;        $fansrank =  db_select($fansrank_sql,array(),'fromuid');        foreach ($fansrank as $k=>$c){                $fansrank[$k]['rank'] = (($page-1)*PAGE_LIMIT)+$rank;                $fansrank[$k]['nickname'] =  self::getNickname($c['nickname'],12);                $worker_name = self::getWorkerName($alldata_settings,$c['workerid']);                $fansrank[$k]['worker_name'] = $worker_name;                $rank++;            }        //        $uids = array_keys($fansrank);        //        $uids_str = '';        //        if($uids){        //            $uids_str = implode(',',$uids);        //        }        //        $fans_sql = "SELECT uid,avatar,nickname,workerid FROM ".tablename(t_fans)." WHERE uid in ({$uids_str}) ";        //        $fans_all_list = db_select($fans_sql,array(),'uid');        //        $rank = 1;        //        foreach ($fansrank as $k=>$c){        //            $fans_info = $fans_all_list[$k];        //            $fansrank[$k]['rank'] = (($page-1)*PAGE_LIMIT)+$rank;        //            $fansrank[$k]['avatar'] = $fans_info['avatar'];        //            $fansrank[$k]['nickname'] = $fans_info['nickname'];        //            $worker_name = self::getWorkerName($alldata_settings,$c['workerid']);        //            $fansrank[$k]['worker_name'] = $worker_name;        //            $rank++;        //        }        $fansrank = array_values($fansrank);    }else{        if($workerids) {            $not_fromuid_where = " and fromuid not in ($workerids)";        }        $where = " AND nickname!='新用户' AND nickname!='微信用户' and nickname!='不在活动地区' AND status <> -3  AND uid>0 AND avatar IS NOT NULL                    AND avatar != '' AND avatar != 'https://css2020.yixuan.net/2020css/yx2020/images/question.png'";        $fans_count = "SELECT count(id) as count FROM " . tablename (t_fans) . " WHERE {$all_where}  {$not_fromuid_where} {$where}";        $count =  db_fetchcolumn($fans_count);        //查询数量        if($count){            $total_page = ceil($count/PAGE_LIMIT);        }else{            $total_page = 1;        }        $fansrank_sql = "SELECT uid,avatar,nickname,scansum,forward,lightsum,workerid FROM " . tablename(t_fans)            . " WHERE {$all_where}  {$not_fromuid_where} {$where}  ORDER BY lightsum DESC,addtime ASC LIMIT " . $page_start.','. PAGE_LIMIT;        $fansrank =  db_select($fansrank_sql);        foreach ($fansrank as $k=> $v){            $fansrank[$k]['rank'] = (($page-1)*PAGE_LIMIT)+$k+1;            $worker_name = self::getWorkerName($alldata_settings,$v['workerid']);            $fansrank[$k]['worker_name'] = $worker_name;        }    }    return [        'list' => $fansrank,        'total_page' => $total_page    ];}//团长排名function tuanRankList($alldata_settings,$all_where,$addtime_where,$page,$order_field ='tuannum',$order_type = 2){    $page_start = ($page-1)*PAGE_LIMIT;    $order_type = $order_type==1?'ASC':'DESC';    $order = $order_field.' '.$order_type;    $where = " AND nickname!='新用户' AND nickname!='微信用户' and nickname!='不在活动地区' AND uid>0 AND avatar IS NOT NULL               AND avatar != '' AND avatar != 'https://css2020.yixuan.net/2020css/yx2020/images/question.png'";    $count_sql = "SELECT count(id) as count FROM ".tablename(t_record)." WHERE {$all_where} {$addtime_where} {$where} and status > 0 and type = 0 ";    $count =  db_fetchcolumn($count_sql);    //查询数量    if($count){        $total_page = ceil($count/PAGE_LIMIT);    }else{        $total_page = 1;    }    $tuanrank_sql = "SELECT avatar,nickname,tuannum,workerid FROM ".tablename(t_record)."                     WHERE {$all_where} {$addtime_where} {$where} and status > 0 and type = 0                       ORDER BY {$order},addtime asc  LIMIT " . $page_start.','. PAGE_LIMIT;    $tuanrank =  db_select($tuanrank_sql);    foreach ($tuanrank as $k=> $v){        $tuanrank[$k]['rank'] = (($page-1)*PAGE_LIMIT)+$k+1;        $tuanrank[$k]['nickname'] =  self::getNickname($v['nickname'],12);        $worker_name = self::getWorkerName($alldata_settings,$v['workerid']);        $tuanrank[$k]['worker_name'] = $worker_name;    }    return [        'list' => $tuanrank,        'total_page' => $total_page    ];}//红包排名function commRankList($alldata_settings,$all_where,$addtime_where,$page,$order_field ='comm_num',$order_type = 2){    $page_start = ($page-1)*PAGE_LIMIT;    $order_type = $order_type==1?'ASC':'DESC';    $order = $order_field.' '.$order_type;    $count_sql = "SELECT count(distinct(uid)) as count  FROM ".tablename(t_comm)." WHERE {$all_where} {$addtime_where} and status  = 1 ";    $count =  db_fetchcolumn($count_sql);    //查询数量    if($count){        $total_page = ceil($count/PAGE_LIMIT);    }else{        $total_page = 1;    }    $comm_sql = "SELECT uid,count(*) as comm_num,sum(fee) as comm_fee  FROM " . tablename(t_comm)        . " WHERE {$all_where} {$addtime_where} and status = 1                   GROUP BY uid ORDER BY {$order},addtime ASC LIMIT " . $page_start.','. PAGE_LIMIT;    $commrank = db_select($comm_sql,array(),'uid');    $uids = array_keys($commrank);    $uids_str = '';    if($uids){        $uids_str = implode(',',$uids);    }    $comm_fans = "SELECT uid,avatar,nickname,workerid FROM ".tablename(t_fans)." WHERE uid in ({$uids_str})";    $comm_fans_list = db_select($comm_fans,array(),'uid');    $rank = 1;    foreach ($commrank as $k=>$c){        $fans_info =  $comm_fans_list[$k];        $commrank[$k]['rank'] = (($page-1)*PAGE_LIMIT)+$rank;        $commrank[$k]['avatar'] = $fans_info['avatar'];        $commrank[$k]['nickname'] =  self::getNickname($fans_info['nickname'],12);        $worker_name = self::getWorkerName($alldata_settings,$c['workerid']);        $commrank[$k]['worker_name'] = $worker_name;        $rank++;    }    $commrank = array_values($commrank);    return [        'list' => $commrank,        'total_page' => $total_page    ];}//百度语音播报function baiduAudio(){    #######################################################    ###baidu百度帐号：沂水亲亲宝贝 手机：19963159099 密码Lc001213    #######################################################    # 填写网页上申请的appkey 如 $apiKey="g8eBUMSokVB1BHGmgxxxxxx"    $apiKey = "uQKMo9WXfqhP3gj0weSiC9eB";    # 填写网页上申请的APP SECRET 如 $secretKey="94dc99566550d87f8fa8ece112xxxxx"    $secretKey = "KA9H3hHBCafMcuLI6v3sryOr9AMvHUIH";    # text 的内容为"欢迎使用百度语音合成"的urlencode,utf-8 编码    # 可以百度搜索"urlencode"    // $text2 = iconv("UTF-8", "GBK", $text);    // echo "text length :" . mb_strlen($text2, "GBK") . "\n";    # 发音人选择, 基础音库：0为度小美，1为度小宇，3为度逍遥，4为度丫丫，    # 精品音库：5为度小娇，103为度米朵，106为度博文，110为度小童，111为度小萌，默认为度小美    $per = 0;    #语速，取值0-15，默认为5中语速    $spd = 5;    #音调，取值0-15，默认为5中语调    $pit = 5;    #音量，取值0-9，默认为5中音量    $vol = 9;    // 下载的文件格式, 3：mp3(default) 4： pcm-16k 5： pcm-8k 6. wav    $aue = 3;    $formats = array(3 => 'mp3', 4 => 'pcm', 5 =>'pcm', 6 => 'wav');    $format = $formats[$aue];    $cuid = "123456PHP";    /** 公共模块获取token开始 */    $auth_url = "https://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials&client_id=".$apiKey."&client_secret=".$secretKey;    $ch = curl_init();    curl_setopt($ch, CURLOPT_URL, $auth_url);    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //信任任何证书    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // 检查证书中是否设置域名,0不验证    curl_setopt($ch, CURLOPT_VERBOSE, DEMO_CURL_VERBOSE);    $res = curl_exec($ch);    if(curl_errno($ch))    {        print curl_error($ch);    }    curl_close($ch);    // echo "Token URL response is " . $res . "\n";    $response = json_decode($res, true);    if (!isset($response['access_token'])){        echo "ERROR TO OBTAIN TOKEN\n";        exit(1);    }    if (!isset($response['scope'])){        echo "ERROR TO OBTAIN scopes\n";        exit(2);    }    if (!in_array('audio_tts_post',explode(" ", $response['scope']))){        echo "DO NOT have tts permission\n";        // 请至网页上应用内开通语音合成权限        exit(3);    }    $token = $response['access_token'];    // echo "token = $token ; expireInSeconds: ${response['expires_in']}\n\n";    /** 公共模块获取token结束 */    /** 拼接参数开始 **/    // tex=$text&lan=zh&ctp=1&cuid=$cuid&tok=$token&per=$per&spd=$spd&pit=$pit&vol=$vol    $params = array(        // 'tex' => urlencode($text), // 为避免+等特殊字符没有编码，此处需要2次urlencode。        'per' => $per,        'spd' => $spd,        'pit' => $pit,        'vol' => $vol,        'aue' => $aue,        'cuid' => $cuid,        'tok' => $token,        'lan' => 'zh', //固定参数        'ctp' => 1, // 固定参数    );    $paramsStr =  http_build_query($params);    $url = 'http://tsn.baidu.com/text2audio';    $yxurl = $url . '?' . $paramsStr . "&tex=";    return $yxurl;}//$sign 1正截取 2负截取function getNickname($nickname,$length=5,$sign = 1){    preg_match_all('/[\x{4e00}-\x{9fff}]+/u', $nickname, $content);    $username = implode('',$content[0]);    if (empty($username)){$username = $nickname;}    $username = str_replace('易宣软件','',$username);    $username = str_replace('易宣','',$username);    if($sign==1){        $username = mb_substr($username,0,$length,'utf-8');    }else{        $username = mb_substr($username,-$length);    }    return $username;}//获取员工信息function getWorkerName($alldata_settings,$workerid){    $shangjia_list = $alldata_settings['shangjia_list'];    $team_list = $alldata_settings['team_list'];    $worker_list = $alldata_settings['worker_list'];    $themeid = DAPING_THEMEID;    $themeid_worker = $themeid.'_'.$workerid;    if(isset($worker_list[$themeid_worker])){        $worker_info = $worker_list[$themeid_worker];        $worker_name = $worker_info['username'];        $team_name = '';        if(isset($team_list[$worker_info['team']])){            $team_name = $team_list[$worker_info['team']]['name'].'-';        }        $company_name = '';        if(isset($shangjia_list[$worker_info['company']])){            $company_name = $shangjia_list[$worker_info['company']]['name'].'-';        }        $worker_name = $company_name.$team_name.$worker_name;    }else{        $worker_name = '无';    }    return $worker_name;}
}